-
Notifications
You must be signed in to change notification settings - Fork 54
Add operand in ternary operators rule #39
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
Add operand in ternary operators rule #39
Conversation
@dmitrydymarchuk This is already handled by https://github.com/slevomat/coding-standard#slevomatcodingstandardcontrolstructuresdisallowshortternaryoperator-. Also, using the short ternary operator ?: isn't really safe, as you can hide some boolean cases inside the first member.
15aa3fa to
0edc460
Compare
@carusogabriel PHPStan can be used without PHP CodeSniffer. I think phpstan-strict-rules should return error for shorthand operator in this case.
32c1d88 to
e193d17
Compare
caf5ad7 to
4c0f978
Compare
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.
Hi, I agree with this part If and else parts of ternary operator are equal (%s). but not with Ternary operator is not needed.. PHPStan isn't a codestyle tool so this requirement is too opinionated.
ecb1ffa to
cf13bd7
Compare
cf13bd7 to
198546b
Compare
Ternary operator is not needed.
This part was removed
Thank you!
Hi, unfortunately I had to revert this rule (03807e3). It finds false positives in cases like:
function (\stdClass $a, \stdClass $b): void { rand(0, 1) ? [$a] : [$b]; };
Unfortunately PHPStan\Type\Type has no method to handle these scenarios which would be required to check whether some value is identical or not.
Uh oh!
There was an error while loading. Please reload this page.
Find unnecessary ternary operators, when if and else part are equal or if and else part could be replaced by condition casted to bool.