function ArrayEntryToken::convertArrayAccessToEntry
Converts instance of \ArrayAccess to key => value array entry
Parameters
\ArrayAccess<array-key, mixed> $object:
Return value
array<mixed>
Throws
1 call to ArrayEntryToken::convertArrayAccessToEntry()
- ArrayEntryToken::scoreArgument in vendor/
phpspec/ prophecy/ src/ Prophecy/ Argument/ Token/ ArrayEntryToken.php - 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.
File
-
vendor/
phpspec/ prophecy/ src/ Prophecy/ Argument/ Token/ ArrayEntryToken.php, line 130
Class
- ArrayEntryToken
- Array entry token.
Namespace
Prophecy\Argument\TokenCode
private function convertArrayAccessToEntry(\ArrayAccess $object) {
if (!$this->key instanceof ExactValueToken) {
throw new InvalidArgumentException(sprintf('You can only use exact value tokens to match key of ArrayAccess object' . PHP_EOL . 'But you used `%s`.', $this->key));
}
$key = $this->key
->getValue();
if (!\is_int($key) && !\is_string($key)) {
throw new InvalidArgumentException(sprintf('You can only use integer or string keys to match key of ArrayAccess object' . PHP_EOL . 'But you used `%s`.', $this->key));
}
return $object->offsetExists($key) ? array(
$key => $object[$key],
) : array();
}