Adds nested Higher Order Expectations.

This commit is contained in:
luke
2021-06-16 20:48:23 +01:00
parent 729638a3bb
commit 7ff64540a6
8 changed files with 128 additions and 53 deletions

View 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;
}
}