Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ArrayEntryToken.php

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

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);
    
    /** @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));
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal