You are here

public function ArrayEntryToken::scoreArgument in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpspec/prophecy/src/Prophecy/Argument/Token/ArrayEntryToken.php \Prophecy\Argument\Token\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

array|\ArrayAccess|\Traversable $argument:

Return value

bool|int

Throws

\Prophecy\Exception\InvalidArgumentException

Overrides TokenInterface::scoreArgument

File

vendor/phpspec/prophecy/src/Prophecy/Argument/Token/ArrayEntryToken.php, line 47

Class

ArrayEntryToken
Array entry token.

Namespace

Prophecy\Argument\Token

Code

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);
  $scoreEntry = function ($value, $key) {
    return $value && $key ? min(8, ($key + $value) / 2) : false;
  };
  return max(array_map($scoreEntry, $valueScores, $keyScores));
}