Repository navigation
[Php80] Skip loose comparisons that differ from strict on StrStartsWithRector and StrEndsWithRector #8643
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
Closed
guillaume-sainthillier
wants to merge
1
commit into
rectorphp:main
from
guillaume-sainthillier:strstartswith-skip-loose-comparison
Closed
[Php80] Skip loose comparisons that differ from strict on StrStartsWithRector and StrEndsWithRector #8643
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
31 changes: 0 additions & 31 deletions
31
rules-tests/Php80/Rector/Identical/StrEndsWithRector/Fixture/fixture_equal.php.inc
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
...-tests/Php80/Rector/Identical/StrEndsWithRector/Fixture/skip_loose_numeric_string.php.inc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture; | ||
|
|
||
| class SkipLooseNumericString | ||
| { | ||
| public function run($haystack) | ||
| { | ||
| // '+1' == '01' is true | ||
| $isMatch = substr($haystack, -2) == '01'; | ||
| } | ||
| } | ||
|
|
||
| ?> |
15 changes: 15 additions & 0 deletions
15
rules-tests/Php80/Rector/Identical/StrEndsWithRector/Fixture/skip_loose_substr.php.inc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture; | ||
|
|
||
| class SkipLooseSubstr | ||
| { | ||
| public function run() | ||
| { | ||
| $isMatch = substr($haystack, -strlen($needle)) == $needle; | ||
|
|
||
| $isMatch = $needle == substr($haystack, -strlen($needle)); | ||
| } | ||
| } | ||
|
|
||
| ?> | ||
15 changes: 15 additions & 0 deletions
15
...sts/Php80/Rector/Identical/StrEndsWithRector/Fixture/skip_loose_substr_not_prefix.php.inc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture; | ||
|
|
||
| class SkipLooseSubstrNotPrefix | ||
| { | ||
| public function run() | ||
| { | ||
| $isNotMatch = substr($haystack, -strlen($needle)) != $needle; | ||
|
|
||
| $isNotMatch = $needle != substr($haystack, -strlen($needle)); | ||
| } | ||
| } | ||
|
|
||
| ?> |
31 changes: 0 additions & 31 deletions
31
rules-tests/Php80/Rector/Identical/StrEndsWithRector/Fixture/substr_not_equal_prefix.php.inc
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
rules-tests/Php80/Rector/Identical/StrStartsWithRector/Fixture/fixture_equal.php.inc
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
rules-tests/Php80/Rector/Identical/StrStartsWithRector/Fixture/not_equal_substr.php.inc
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
rules-tests/Php80/Rector/Identical/StrStartsWithRector/Fixture/other_side_equal.php.inc
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
...ts/Php80/Rector/Identical/StrStartsWithRector/Fixture/skip_loose_not_equal_substr.php.inc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\Php80\Rector\Identical\StrStartsWithRector\Fixture; | ||
|
|
||
| class SkipLooseNotEqualSubstr | ||
| { | ||
| public function run() | ||
| { | ||
| $isNotMatch = substr($haystack, 0, strlen($needle)) != $needle; | ||
| } | ||
| } | ||
|
|
||
| ?> |
14 changes: 14 additions & 0 deletions
14
...ests/Php80/Rector/Identical/StrStartsWithRector/Fixture/skip_loose_numeric_string.php.inc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\Php80\Rector\Identical\StrStartsWithRector\Fixture; | ||
|
|
||
| class SkipLooseNumericString | ||
| { | ||
| public function run($haystack) | ||
| { | ||
| // '+1' == '01' is true | ||
| $isMatch = substr($haystack, 0, 2) == '01'; | ||
| } | ||
| } | ||
|
|
||
| ?> |
13 changes: 13 additions & 0 deletions
13
rules-tests/Php80/Rector/Identical/StrStartsWithRector/Fixture/skip_loose_strpos.php.inc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\Php80\Rector\Identical\StrStartsWithRector\Fixture; | ||
|
|
||
| class SkipLooseStrpos | ||
| { | ||
| public function run() | ||
| { | ||
| $isMatch = strpos($haystack, $needle) == 0; | ||
| } | ||
| } | ||
|
|
||
| ?> |
13 changes: 13 additions & 0 deletions
13
...ts/Php80/Rector/Identical/StrStartsWithRector/Fixture/skip_loose_strpos_hardcoded.php.inc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\Php80\Rector\Identical\StrStartsWithRector\Fixture; | ||
|
|
||
| class SkipLooseStrposHardcoded | ||
| { | ||
| public function run() | ||
| { | ||
| $isMatch = strpos($haystack, 'hardcoded') == 0; | ||
| } | ||
| } | ||
|
|
||
| ?> |
13 changes: 13 additions & 0 deletions
13
...s/Php80/Rector/Identical/StrStartsWithRector/Fixture/skip_loose_strpos_not_prefix.php.inc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\Php80\Rector\Identical\StrStartsWithRector\Fixture; | ||
|
|
||
| class SkipLooseStrposNotPrefix | ||
| { | ||
| public function run() | ||
| { | ||
| $notMatch = strpos($haystack, $needle) != 0; | ||
| } | ||
| } | ||
|
|
||
| ?> |
13 changes: 13 additions & 0 deletions
13
...s/Php80/Rector/Identical/StrStartsWithRector/Fixture/skip_loose_strpos_other_side.php.inc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\Php80\Rector\Identical\StrStartsWithRector\Fixture; | ||
|
|
||
| class SkipLooseStrposOtherSide | ||
| { | ||
| public function run() | ||
| { | ||
| $isMatch = 0 == strpos($haystack, $needle); | ||
| } | ||
| } | ||
|
|
||
| ?> |
13 changes: 13 additions & 0 deletions
13
rules-tests/Php80/Rector/Identical/StrStartsWithRector/Fixture/skip_loose_substr.php.inc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\Php80\Rector\Identical\StrStartsWithRector\Fixture; | ||
|
|
||
| class SkipLooseSubstr | ||
| { | ||
| public function run() | ||
| { | ||
| $isMatch = substr($haystack, 0, strlen($needle)) == $needle; | ||
| } | ||
| } | ||
|
|
||
| ?> |
15 changes: 15 additions & 0 deletions
15
...s/Php80/Rector/Identical/StrStartsWithRector/Fixture/skip_loose_substr_other_side.php.inc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\Php80\Rector\Identical\StrStartsWithRector\Fixture; | ||
|
|
||
| class SkipLooseSubstrOtherSide | ||
| { | ||
| public function run() | ||
| { | ||
| $isMatch = $needle == substr($haystack, 0, strlen($needle)); | ||
|
|
||
| $isNotMatch = $needle != substr($haystack, 0, strlen($needle)); | ||
| } | ||
| } | ||
|
|
||
| ?> |
27 changes: 0 additions & 27 deletions
27
rules-tests/Php80/Rector/Identical/StrStartsWithRector/Fixture/strpos_equal.php.inc
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
...-tests/Php80/Rector/Identical/StrStartsWithRector/Fixture/strpos_equal_not_prefix.php.inc
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
...-tests/Php80/Rector/Identical/StrStartsWithRector/Fixture/strpos_equal_other_side.php.inc
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can you revert this? While technically it's correct removal, in legacy projects where this change would be valid most people use
==.