-
Notifications
You must be signed in to change notification settings - Fork 547
Simplify by replacing chained $var === const with in_array()
#4098
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
Simplify by replacing chained $var === const with in_array()
#4098
Conversation
$var === const with in_array()Refactor/or idetical chain to in array()$var === const with in_array()
ondrejmirtes
left a comment
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.
Great idea! I'll merge it after this fix.
|
|
||
| public function __construct( | ||
| #[AutowiredParameter] | ||
| private PhpPrinter $printer, |
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.
Do not make this a DI service. Ask for ExprPrinter instead which is already a DI service.
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.
Thanks, I replaced it with ExprPrinter.
6044c89 to
1b0b7d4
Compare
|
I see, the error that occurred after rebasing seems to be independent of the changes in this PR. |
|
This pull request has been marked as ready for review. |
build/PHPStan/Build/OrChainIdenticalComparisonToInArrayRule.php
Outdated
Show resolved
Hide resolved
|
Thank you! An idea: Generalize this rule to also account for |
This is the same change as the previous one at #2618, but it will be automatically refactored by rules 🤖.
Currently,
return $var === 'foo' || $var === 'bar';and$isFooOrBar = $var === 'foo' || $var === 'bar';are not covered. It also does not support formulas replaced by De Morgan's laws.