From 7fd43922af2ce8f9f62fdd0a3f1a434371010e99 Mon Sep 17 00:00:00 2001 From: Daniel Coulbourne Date: Wed, 22 Nov 2023 00:56:27 -0500 Subject: [PATCH 1/2] Add support for interfaces in the expectsParameters check on MethodFinder. --- src/Facades/Verbs.php | 2 +- src/Support/MethodFinder.php | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Facades/Verbs.php b/src/Facades/Verbs.php index ce476cd2..4f293d2c 100644 --- a/src/Facades/Verbs.php +++ b/src/Facades/Verbs.php @@ -11,7 +11,7 @@ * @method static bool isReplaying() * @method static void unlessReplaying(callable $callback) * @method static bool isReplaying() - * @method static int|string toId($id) + * @method static int|string|null toId($id) * @method static Event fire(Event $event) */ class Verbs extends Facade diff --git a/src/Support/MethodFinder.php b/src/Support/MethodFinder.php index 31b7e2f1..adc608e5 100644 --- a/src/Support/MethodFinder.php +++ b/src/Support/MethodFinder.php @@ -71,12 +71,28 @@ protected function expectsParameters(ReflectionMethod $method): bool } foreach ($method->getParameters() as $parameter) { - $expected = collect(Reflector::getParameterClassNames($parameter)); - $matches = $expected->intersect($this->types)->count(); + $typeHint = Reflector::getParameterClassNames($parameter); + $expected = collect($typeHint); - if ($matches < $expected->count() || $matches < $this->types->count()) { - return false; + $direct_matches = $expected->intersect($this->types); + + + if ($direct_matches->isNotEmpty()) { + return true; + } + + $interface_matches = $this + ->types + ->map(fn ($type) => class_implements($type)) + ->flatten() + ->unique() + ->intersect($expected); + + if ($interface_matches->isNotEmpty()) { + return true; } + + return false; } return true; From 2d06521d15d29fbcab88fe87fdc864d5afc8534f Mon Sep 17 00:00:00 2001 From: DanielCoulbourne Date: Wed, 22 Nov 2023 05:56:58 +0000 Subject: [PATCH 2/2] Fix styling --- src/Support/MethodFinder.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Support/MethodFinder.php b/src/Support/MethodFinder.php index adc608e5..eb611a42 100644 --- a/src/Support/MethodFinder.php +++ b/src/Support/MethodFinder.php @@ -76,7 +76,6 @@ protected function expectsParameters(ReflectionMethod $method): bool $direct_matches = $expected->intersect($this->types); - if ($direct_matches->isNotEmpty()) { return true; } @@ -91,7 +90,7 @@ protected function expectsParameters(ReflectionMethod $method): bool if ($interface_matches->isNotEmpty()) { return true; } - + return false; }