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

Breadcrumb

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

function ArrayEntryToken::convertArrayAccessToEntry

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

Parameters

\ArrayAccess<array-key, mixed> $object:

Return value

array<mixed>

Throws

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 130

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();
    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();
}

API Navigation

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