You are here

private function ArrayEntryToken::convertArrayAccessToEntry 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::convertArrayAccessToEntry()

Converts instance of \ArrayAccess to key => value array entry

Parameters

\ArrayAccess $object:

Return value

array|null

Throws

\Prophecy\Exception\InvalidArgumentException

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 129

Class

ArrayEntryToken
Array entry token.

Namespace

Prophecy\Argument\Token

Code

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();
  return $object
    ->offsetExists($key) ? array(
    $key => $object[$key],
  ) : array();
}