Repository navigation
[Php80] Skip loose false comparison in StrContainsRector and MbStrContainsRector - #8641
guillaume-sainthillier wants to merge 3 commits into
Conversation
ebb72bb to
b222c80
Compare
|
Just quick look, it seems it looks like academic use case on loose comparison use on that purpose, which mostly false negative. Most of the time, the usage is intended as str contains needs I guess. |
|
Fair point that the intent is almost always "contains". The |
…ns-skip-loose-comparison # Conflicts: # rules-tests/Php80/Rector/NotIdentical/MbStrContainsRector/Fixture/offset_variable_zero_equal_strpos.php.inc # rules/Php80/Rector/NotIdentical/MbStrContainsRector.php
…ns-skip-loose-comparison # Conflicts: # rules-tests/Php80/Rector/NotIdentical/StrContainsRector/Fixture/offset_variable_zero_equal_strpos.php.inc
|
I agree with @samsonasik . Can you revert that part? In real projects the same stucture would be converted manually to one we do here. |
|
Makes sense, thanks both. Closing, as reverting the loose-comparison part leaves nothing in this PR. |
|
Thanks for the ping though! It's always better to have these battle tested. What legacy project do you work on that you've found these? |
|
For this PR it was only "theoretical" :) I will let you know if I find real use cases from some legacy php 5.2 projects |
|
Ah, I thought you had some troubles :) I prefer real projects over theory, as we try to be practical tool, with as few rules as possible to deliver speed to most projects. |
Loose comparisons to
false(added in #3246) are not equivalent tostr_contains():So
strpos($haystack, $needle) != false(or== false) is rewritten to code with a different result whenever the needle is at the start. Same formb_strpos()/mb_strstr()inMbStrContainsRector.Change: both rules only handle
===/!==again. Loose fixtures becameskip_loose_*; theoffset_*_equal_*fixtures were removed as they now duplicate the skip.