function Context::addArray
1 call to Context::addArray()
- Context::add in vendor/
sebastian/ recursion-context/ src/ Context.php - @psalm-template T
File
-
vendor/
sebastian/ recursion-context/ src/ Context.php, line 78
Class
Namespace
SebastianBergmann\RecursionContextCode
private function addArray(array &$array) : int {
$key = $this->containsArray($array);
if ($key !== false) {
return $key;
}
$key = count($this->arrays);
$this->arrays[] =& $array;
if (!array_key_exists(PHP_INT_MAX, $array) && !array_key_exists(PHP_INT_MAX - 1, $array)) {
$array[] = $key;
$array[] = $this->objects;
}
else {
/* Cover the improbable case, too.
*
* Note that array_slice() (used in containsArray()) will return the
* last two values added, *not necessarily* the highest integer keys
* in the array. Therefore, the order of these writes to $array is
* important, but the actual keys used is not. */
do {
/** @noinspection PhpUnhandledExceptionInspection */
$key = random_int(PHP_INT_MIN, PHP_INT_MAX);
} while (array_key_exists($key, $array));
$array[$key] = $key;
do {
/** @noinspection PhpUnhandledExceptionInspection */
$key = random_int(PHP_INT_MIN, PHP_INT_MAX);
} while (array_key_exists($key, $array));
$array[$key] = $this->objects;
}
return $key;
}