function ArrayEntryToken::scoreArgument
Scores half of combined scores from key and value tokens for same entry. Capped at 8. If argument implements \ArrayAccess without \Traversable, then key token is restricted to ExactValueToken.
Parameters
mixed $argument:
Return value
false|int
Throws
Overrides TokenInterface::scoreArgument
File
-
vendor/
phpspec/ prophecy/ src/ Prophecy/ Argument/ Token/ ArrayEntryToken.php, line 47
Class
- ArrayEntryToken
- Array entry token.
Namespace
Prophecy\Argument\TokenCode
public function scoreArgument($argument) {
if ($argument instanceof \Traversable) {
$argument = iterator_to_array($argument);
}
if ($argument instanceof \ArrayAccess) {
$argument = $this->convertArrayAccessToEntry($argument);
}
if (!is_array($argument) || empty($argument)) {
return false;
}
$keyScores = array_map(array(
$this->key,
'scoreArgument',
), array_keys($argument));
$valueScores = array_map(array(
$this->value,
'scoreArgument',
), $argument);
/** @var callable(int|false, int|false): (int|false) $scoreEntry */
$scoreEntry = function ($value, $key) {
return $value && $key ? min(8, ($key + $value) / 2) : false;
};
return max(array_map($scoreEntry, $valueScores, $keyScores));
}