Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Correct return type to match functionality #54148

Merged
merged 1 commit into from
Jan 10, 2025

Conversation

willpower232
Copy link
Contributor

As discussed in #50766 (comment), the revised return type is still incorrect as it needs to include both string and closure in order to match all the functionality available.

I was fortunate enough to be upgrading a project where I ended up using all three types so I can confirm that phpstan is now happy with this particular combination.

The docs don't reference another type currently so this should be sufficient.

@@ -7,7 +7,7 @@ interface HasMiddleware
/**
* Get the middleware that should be assigned to the controller.
*
* @return \Illuminate\Routing\Controllers\Middleware[]
* @return array<int,\Illuminate\Routing\Controllers\Middleware|\Closure|string>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this have sufficed?

Suggested change
* @return array<int,\Illuminate\Routing\Controllers\Middleware|\Closure|string>
* @return (\Illuminate\Routing\Controllers\Middleware|\Closure|string)[]

Copy link
Contributor

@shaedrich shaedrich Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, is string the closest we can get? Have you tried callable?

Suggested change
* @return array<int,\Illuminate\Routing\Controllers\Middleware|\Closure|string>
* @return array<int,\Illuminate\Routing\Controllers\Middleware|callable>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using (...)[] seems to work just as well but I can't say I have seen that syntax before and tend to defer to the error output from phpstan which currently uses array<...>

it does seem I can remove \Closure|string and replace with callable so that is a nice improvement

I have also seen list<...> is valid now so technically @return list<\Illuminate\Routing\Controllers\Middleware|callable> is an option in this case

I'll wait for github to support polls and or others to vote on the best combination and way forward 😅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would actually be great for such cases 😂👍🏻

@taylorotwell taylorotwell merged commit 3a9daf2 into laravel:11.x Jan 10, 2025
40 checks passed
@willpower232 willpower232 deleted the patch-1 branch January 13, 2025 09:37
@willpower232
Copy link
Contributor Author

Thanks!

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

Successfully merging this pull request may close these issues.

3 participants