Closed tatitati closed 4 years ago
I think the answer is in your post - Yoda style helps avoid unintended dangerous variable assignments. But your example is a comparison against a function call, which you cannot accidentally assign in PHP. The Yoda style rule is there to help devs proactively defend against typos that are difficult to spot and debug, but as your example can't be dangerous, I don't think it should apply in this case.
Closing this one off for now - happy to revisit the discussion if needed in the future!
@djoos Hey!
What about this?
if ($args['type'] == 1) {....}
YODA rule also would not trigger in this case due to shiff logic
if (T_VARIABLE === $tokens[$comparison - 2]['code'] && T_VARIABLE !== $tokens[$comparison + 2]['code'] ) {
For this if ($args == 1) {....}
YODA rule WILL works.
I know that YODA comparation tries to avoid a bad assignation to a variable. But also is an standard saying that the expected value should be on the left (first) when comparing.
This said, in my case I can do this without simple variables and phpcs doesn't complain:
I think in this case also should complain. This makes the code more standard having all the expected values on the left.