Skip to content

Commit

Permalink
Add support for interfaces in the expectsParameters check on MethodFi…
Browse files Browse the repository at this point in the history
…nder.
  • Loading branch information
DanielCoulbourne committed Nov 22, 2023
1 parent ae842d2 commit 7fd4392
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Facades/Verbs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 20 additions & 4 deletions src/Support/MethodFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7fd4392

Please sign in to comment.