-
Notifications
You must be signed in to change notification settings - Fork 473
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
Report useless return values of function calls #3225
Conversation
e594397
to
34336f3
Compare
This pull request has been marked as ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separate rule please. Same level the void
usage is reported (not sure from the top of my head).
its a level 0 error: https://phpstan.org/r/42b76642-82b2-422a-bd7d-f3678eb6e1b0 |
3d864f7
to
51d7783
Compare
I have no idea why the PHP7.2 build fails with a "risky error". maybe its related that I ran the levels-tests on a windows machine. |
public function testUselessReturnValuePhp8(): void | ||
{ | ||
if (PHP_VERSION_ID < 80000) { | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't how to make test for >= 80000
only. You need to call markTestSkipped. See many examples in other tests. This is why it's marked as risky.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ouch. great catch, thanks.
if (count($reorderedArgs) === 1 || (count($reorderedArgs) >= 2 && $scope->getType($reorderedArgs[1]->value)->isFalse()->yes())) { | ||
return [RuleErrorBuilder::message( | ||
sprintf( | ||
'Return value of function %s is always true and the result is printed instead of being returned. Pass in true as parameter #%d $%s to return the output instead.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put ()
after %s
. So that it's print_r()
and not just print_r
.
This reverts commit 51d77837680354b704b9f419358f79ebe58e6b2e.
in phpstorm stubs I found another function alias worth reporting: show_source() |
just realized the PrestaShop/PrestaShop shows 5 real world errors this rule is targetting, simlar to the one of my initial report 💪 |
Nice! I really like this addition. |
Thank you. |
closes phpstan/phpstan#11320