Skip to content

Commit

Permalink
Update ValidatorList.php
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere authored Dec 26, 2017
1 parent b4defa8 commit b70c0f2
Showing 1 changed file with 6 additions and 22 deletions.
28 changes: 6 additions & 22 deletions src/ValidatorList.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ public static function isArray($val)
}

/**
* 验证值是否是一个非自然数组 map (key - value 形式的)
* 验证值是否是一个非自然数组 map (key不是自然增长的 OR key - value 形式的)
* @param mixed $val
* @return bool
*/
Expand All @@ -529,13 +529,9 @@ public static function isMap($val)
}

/** @var array $val */
foreach ($val as $k => $v) {
if (\is_string($k)) {
return true;
}
}

return false;
$keys = array_keys($val);

return array_keys($keys) !== $keys;
}

/**
Expand All @@ -549,22 +545,10 @@ public static function isList($val)
return false;
}

$prevKey = 0;

/** @var array $val */
foreach ($val as $k => $v) {
if (!\is_int($k)) {
return false;
}

if ($k !== $prevKey) {
return false;
}

$prevKey++;
}
$keys = array_keys($val);

return true;
return array_keys($keys) === $keys;
}

/**
Expand Down

0 comments on commit b70c0f2

Please sign in to comment.