You are here

class ArrayEveryEntryToken in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpspec/prophecy/src/Prophecy/Argument/Token/ArrayEveryEntryToken.php \Prophecy\Argument\Token\ArrayEveryEntryToken

Array every entry token.

@author Adrien Brault <adrien.brault@gmail.com>

Hierarchy

Expanded class hierarchy of ArrayEveryEntryToken

File

vendor/phpspec/prophecy/src/Prophecy/Argument/Token/ArrayEveryEntryToken.php, line 19

Namespace

Prophecy\Argument\Token
View source
class ArrayEveryEntryToken implements TokenInterface {

  /**
   * @var TokenInterface
   */
  private $value;

  /**
   * @param mixed $value exact value or token
   */
  public function __construct($value) {
    if (!$value instanceof TokenInterface) {
      $value = new ExactValueToken($value);
    }
    $this->value = $value;
  }

  /**
   * {@inheritdoc}
   */
  public function scoreArgument($argument) {
    if (!$argument instanceof \Traversable && !is_array($argument)) {
      return false;
    }
    $scores = array();
    foreach ($argument as $key => $argumentEntry) {
      $scores[] = $this->value
        ->scoreArgument($argumentEntry);
    }
    if (empty($scores) || in_array(false, $scores, true)) {
      return false;
    }
    return array_sum($scores) / count($scores);
  }

  /**
   * {@inheritdoc}
   */
  public function isLast() {
    return false;
  }

  /**
   * {@inheritdoc}
   */
  public function __toString() {
    return sprintf('[%s, ..., %s]', $this->value, $this->value);
  }

  /**
   * @return TokenInterface
   */
  public function getValue() {
    return $this->value;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ArrayEveryEntryToken::$value private property
ArrayEveryEntryToken::getValue public function
ArrayEveryEntryToken::isLast public function Returns true if this token prevents check of other tokens (is last one). Overrides TokenInterface::isLast
ArrayEveryEntryToken::scoreArgument public function Calculates token match score for provided argument. Overrides TokenInterface::scoreArgument
ArrayEveryEntryToken::__construct public function
ArrayEveryEntryToken::__toString public function Returns string representation for token. Overrides TokenInterface::__toString