Skip to content

Conversation

calebdw
Copy link
Contributor

@calebdw calebdw commented Aug 18, 2025

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!

@calebdw calebdw force-pushed the calebdw/push-xnproloxrpwm branch 3 times, most recently from bce1c6e to 95a2c2d Compare August 18, 2025 18:44
@calebdw calebdw force-pushed the calebdw/push-xnproloxrpwm branch from 95a2c2d to 2d9f068 Compare August 18, 2025 18:45
@taylorotwell taylorotwell merged commit 6d5dfad into laravel:12.x Aug 19, 2025
60 checks passed
@calebdw calebdw deleted the calebdw/push-xnproloxrpwm branch August 19, 2025 13:37
@rodrigopedra
Copy link
Contributor

Why did you change an unrelated test?

@calebdw
Copy link
Contributor Author

calebdw commented Aug 20, 2025

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

@rodrigopedra
Copy link
Contributor

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.

@calebdw
Copy link
Contributor Author

calebdw commented Aug 20, 2025

I disagree, but what's done is done

@browner12
Copy link
Contributor

could we also safely type the parameters here?

@calebdw
Copy link
Contributor Author

calebdw commented Aug 20, 2025

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 Argument #1 ($foo) must be of type string, null given type errors)

@chris-ware
Copy link
Contributor

Interestingly, this seems to cause an issue with the csrf_token helper method. There appears to be some instances where it doesn't return a string, which now causes a fatal error due to it not being type matched.

@calebdw
Copy link
Contributor Author

calebdw commented Aug 26, 2025

let me take a look

browner12 added a commit to browner12/framework that referenced this pull request Aug 26, 2025
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.
taylorotwell pushed a commit that referenced this pull request Aug 26, 2025
this fully reverts the change from #56684 that was partially reverted in #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.
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.

5 participants