Refactors HigherOrderMessage

This commit is contained in:
luke
2021-07-08 17:30:39 +01:00
parent 7e9edecc7f
commit e45c4ff4f1

View File

@ -70,8 +70,9 @@ final class HigherOrderMessage
*/ */
public function call(object $target) public function call(object $target)
{ {
if (($value = $this->retrieveHigherOrderCallable($target)) !== null) { if ($this->hasHigherOrderCallable()) {
return $value; /* @phpstan-ignore-next-line */
return (new HigherOrderCallables($target))->{$this->methodName}(...$this->arguments);
} }
try { try {
@ -93,18 +94,13 @@ final class HigherOrderMessage
} }
/** /**
* Attempts to call one of the available Higher Order callables if it exists. * Determines whether or not there exists a higher order callable with the message name.
* *
* @return mixed|null * @return bool
*/ */
private function retrieveHigherOrderCallable(object $target) private function hasHigherOrderCallable()
{ {
if (in_array($this->methodName, get_class_methods(HigherOrderCallables::class), true)) { return 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 private static function getUndefinedMethodMessage(object $target, string $methodName): string