mirror of
https://github.com/pestphp/pest.git
synced 2026-03-09 01:07:23 +01:00
Adds nested Higher Order Expectations.
This commit is contained in:
29
src/Concerns/RetrievesValues.php
Normal file
29
src/Concerns/RetrievesValues.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Concerns;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
trait RetrievesValues
|
||||
{
|
||||
/**
|
||||
* Safely retrieve the value at the given key from an object or array.
|
||||
*
|
||||
* @param array<mixed>|object $value
|
||||
* @param mixed $default
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function retrieve(string $key, $value, $default = null)
|
||||
{
|
||||
if (is_array($value)) {
|
||||
return $value[$key] ?? $default;
|
||||
}
|
||||
|
||||
// @phpstan-ignore-next-line
|
||||
return $value->$key ?? $default;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user