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

UselessFunctionReturnValueRule: More precise error message #3266

Merged
merged 3 commits into from
Aug 1, 2024

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Jul 25, 2024

@staabm staabm marked this pull request as ready for review July 25, 2024 13:54
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@takaram
Copy link
Contributor

takaram commented Jul 25, 2024

highlight_string never returns false while its return type is declared as string|bool
PHP 8.4 is going to change it to string|true.
https://github.com/php/php-src/blob/php-8.4.0alpha2/NEWS#L26-L27

highlight_file and show_source may return both true and false, but it means that using the return value is not useless, doesn't it?

@staabm
Copy link
Contributor Author

staabm commented Jul 25, 2024

highlight_file and show_source may return both true and false, but it means that using the return value is not useless, doesn't it?

I am not sure. this might mean we should drop these 2 from the rule

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

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

Yes, highlight_file and show_source should be dropped from this rule. It's more complicated with them.

Instead, these functions could have a stub file with a conditional return type.

Then, someone is free to write a rule that disallows bool and potentially other types to be used in a string context, like concat and others. (But it's a bad fit for PHPStan core because it's not a bug.)

@staabm
Copy link
Contributor Author

staabm commented Aug 1, 2024

Yes, highlight_file and show_source should be dropped from this rule. It's more complicated with them.

done

Instead, these functions could have a stub file with a conditional return type.

we already have these stubs

@ondrejmirtes ondrejmirtes merged commit 35a2f57 into phpstan:1.11.x Aug 1, 2024
221 checks passed
@ondrejmirtes
Copy link
Member

Thank you.

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.

4 participants