class ArrayEveryEntryToken
Array every entry token.
@author Adrien Brault <adrien.brault@gmail.com>
Hierarchy
- class \Prophecy\Argument\Token\ArrayEveryEntryToken implements \Prophecy\Argument\Token\TokenInterface
Expanded class hierarchy of ArrayEveryEntryToken
File
-
vendor/
phpspec/ prophecy/ src/ Prophecy/ Argument/ Token/ ArrayEveryEntryToken.php, line 19
Namespace
Prophecy\Argument\TokenView 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
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
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 |