-
Notifications
You must be signed in to change notification settings - Fork 11.5k
[12.x] feat: add native return types to helper functions #56684
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
Conversation
bce1c6e
to
95a2c2d
Compare
95a2c2d
to
2d9f068
Compare
Why did you change an unrelated test? |
It's not an "unrelated" test---the test was failing with a type error because the helper function was returning a mocked stdClass instead of a mocked ViewFactory like it should have to begin with |
It is unrelated, as the PR title and description fail to mention it and only talk about fixing return types on helpers. That should have been sent on a separate PR. |
I disagree, but what's done is done |
could we also safely type the parameters here? |
That's less safe because the user could be passing in bad data (e.g., could result in |
Interestingly, this seems to cause an issue with the |
let me take a look |
this fully reverts the change from laravel#56684 that was partially reverted in laravel#56773 by adding back the `@return` docblock. clearly this docblock isn't the whole story, but I think it's good to have it back until we fully figure out what the accurate answer is here.
Hello!
This PR adds native return types to the helper functions (where the return type would not be
mixed
).Note
Functions cannot be extended so there should not be any breaks
Motivation
I've been using Rector to automatically upgrade / refactor my codebase---it has the ability to automatically add types, narrow too wide types, etc. However, in most cases it only uses native types to be completely safe during it's refactors---it skips over function calls like these that don't have native return types.
Adding actual return types like this will allow Rector (and other tools) to better understand the return type and be more safe.
Thanks!