Skip to content

Commit

Permalink
Merge pull request #19 from hirethunk/support-interfaces-in-method-fi…
Browse files Browse the repository at this point in the history
…nder

Add support for interfaces in the expectsParameters check on MethodFi…
  • Loading branch information
DanielCoulbourne authored Nov 22, 2023
2 parents ae842d2 + 2d06521 commit f054ce0
Show file tree
Hide file tree
Showing 2 changed files with 20 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
23 changes: 19 additions & 4 deletions src/Support/MethodFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,27 @@ 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 f054ce0

Please sign in to comment.