Adds tap for Higher Order tests

This commit is contained in:
luke
2021-06-24 22:57:26 +01:00
parent 4f67eff619
commit acef002a2d
5 changed files with 78 additions and 5 deletions

View File

@ -70,6 +70,10 @@ final class HigherOrderMessage
*/
public function call(object $target)
{
if (($value = $this->retrieveHigherOrderCallable($target)) !== null) {
return $value;
}
try {
return Reflection::call($target, $this->methodName, $this->arguments);
} catch (Throwable $throwable) {
@ -88,6 +92,21 @@ final class HigherOrderMessage
}
}
/**
* Attempts to call one of the available Higher Order callables if it exists.
*
* @return mixed|null
*/
private function retrieveHigherOrderCallable(object $target)
{
if (in_array($this->methodName, get_class_methods(HigherOrderCallables::class), true)) {
/* @phpstan-ignore-next-line */
return (new HigherOrderCallables($target))->{$this->methodName}(...$this->arguments);
}
return null;
}
private static function getUndefinedMethodMessage(object $target, string $methodName): string
{
if (\PHP_MAJOR_VERSION >= 8) {