Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix issue where union typed parameters caused discovery errors #25

Merged
merged 1 commit into from
Dec 6, 2022

Conversation

27pchrisl
Copy link
Contributor

One of my controllers had a function that could be passed a union type, this caused an error during discovery:

   Error 

  Call to undefined method ReflectionUnionType::getName()

  at vendor/spatie/laravel-route-discovery/src/PendingRoutes/PendingRouteAction.php:54
     50▕     {
     51▕         /** @var ReflectionParameter $modelParameter */
     52▕         $modelParameter = collect($this->method->getParameters())->first(function (ReflectionParameter $parameter) {
     53▕             /** @phpstan-ignore-next-line */
  ➜  54▕             return is_a($parameter->getType()?->getName(), Model::class, true);
     55▕         });
     56▕ 
     57▕         $uri = '';
     58▕ 

This PR fixes the issue by ensuring the type is a ReflectionNamedType before attempting to call getName() on it.

@freekmurze freekmurze merged commit 77b9d67 into spatie:main Dec 6, 2022
@freekmurze
Copy link
Member

Thank you!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants