-
-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PHP80 string helpers loose comparison (#3246)
- Loading branch information
1 parent
0146fc0
commit 6bd6b3c
Showing
42 changed files
with
817 additions
and
63 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
rules-tests/Php80/Rector/Identical/StrEndsWithRector/Fixture/fixture_equal.php.inc
This file contains 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,31 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture; | ||
|
||
class Fixture | ||
{ | ||
public function run() | ||
{ | ||
$isMatch = substr($haystack, -strlen($needle)) == $needle; | ||
|
||
$isMatch = $needle == substr($haystack, -strlen($needle)); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture; | ||
|
||
class Fixture | ||
{ | ||
public function run() | ||
{ | ||
$isMatch = str_ends_with($haystack, $needle); | ||
|
||
$isMatch = str_ends_with($haystack, $needle); | ||
} | ||
} | ||
|
||
?> |
31 changes: 31 additions & 0 deletions
31
rules-tests/Php80/Rector/Identical/StrEndsWithRector/Fixture/hardcoded_equal.php.inc
This file contains 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,31 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture; | ||
|
||
class HardCoded | ||
{ | ||
public function run() | ||
{ | ||
$isMatch = substr($haystack, -3) == 'foo'; | ||
|
||
$isMatch = 'foo' == substr($haystack, -3); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture; | ||
|
||
class HardCoded | ||
{ | ||
public function run() | ||
{ | ||
$isMatch = str_ends_with($haystack, 'foo'); | ||
|
||
$isMatch = str_ends_with($haystack, 'foo'); | ||
} | ||
} | ||
|
||
?> |
31 changes: 31 additions & 0 deletions
31
rules-tests/Php80/Rector/Identical/StrEndsWithRector/Fixture/hardcoded_not_equal.php.inc
This file contains 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,31 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture; | ||
|
||
class HardCodedNotIdentical | ||
{ | ||
public function run() | ||
{ | ||
$isMatch = substr($haystack, -3) != 'foo'; | ||
|
||
$isMatch = 'foo' != substr($haystack, -3); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture; | ||
|
||
class HardCodedNotIdentical | ||
{ | ||
public function run() | ||
{ | ||
$isMatch = !str_ends_with($haystack, 'foo'); | ||
|
||
$isMatch = !str_ends_with($haystack, 'foo'); | ||
} | ||
} | ||
|
||
?> |
13 changes: 13 additions & 0 deletions
13
...p80/Rector/Identical/StrEndsWithRector/Fixture/skip_substr_compare_not_equal_zero.php.inc
This file contains 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\StrEndsWithRector\Fixture; | ||
|
||
class SkipSubstrCompareNotZero | ||
{ | ||
public function run() | ||
{ | ||
$isMatch = substr_compare($haystack, $needle, -strlen($needle)) == 3; | ||
|
||
$isMatch = 3 == substr_compare($haystack, $needle, -strlen($needle)); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
rules-tests/Php80/Rector/Identical/StrEndsWithRector/Fixture/substr_compare_equal.php.inc
This file contains 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,31 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture; | ||
|
||
class SubstrCompare | ||
{ | ||
public function run() | ||
{ | ||
$isMatch = substr_compare($haystack, $needle, -strlen($needle)) == 0; | ||
|
||
$isMatch = 0 == substr_compare($haystack, $needle, -strlen($needle)); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture; | ||
|
||
class SubstrCompare | ||
{ | ||
public function run() | ||
{ | ||
$isMatch = str_ends_with($haystack, $needle); | ||
|
||
$isMatch = str_ends_with($haystack, $needle); | ||
} | ||
} | ||
|
||
?> |
31 changes: 31 additions & 0 deletions
31
...s/Php80/Rector/Identical/StrEndsWithRector/Fixture/substr_compare_equal_hardcoded.php.inc
This file contains 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,31 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture; | ||
|
||
class SubstrCompare | ||
{ | ||
public function run() | ||
{ | ||
$isMatch = substr_compare($haystack, 'needle', -6) == 0; | ||
|
||
$isMatch = 0 == substr_compare($haystack, 'needle', -6); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture; | ||
|
||
class SubstrCompare | ||
{ | ||
public function run() | ||
{ | ||
$isMatch = str_ends_with($haystack, 'needle'); | ||
|
||
$isMatch = str_ends_with($haystack, 'needle'); | ||
} | ||
} | ||
|
||
?> |
31 changes: 31 additions & 0 deletions
31
...s-tests/Php80/Rector/Identical/StrEndsWithRector/Fixture/substr_compare_not_equal.php.inc
This file contains 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,31 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture; | ||
|
||
class SubstrCompareNot | ||
{ | ||
public function run() | ||
{ | ||
$isNotMatch = substr_compare($haystack, $needle, -strlen($needle)) != 0; | ||
|
||
$isNotMatch = 0 != substr_compare($haystack, $needle, -strlen($needle)); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture; | ||
|
||
class SubstrCompareNot | ||
{ | ||
public function run() | ||
{ | ||
$isNotMatch = !str_ends_with($haystack, $needle); | ||
|
||
$isNotMatch = !str_ends_with($haystack, $needle); | ||
} | ||
} | ||
|
||
?> |
31 changes: 31 additions & 0 deletions
31
...p80/Rector/Identical/StrEndsWithRector/Fixture/substr_compare_not_equal_hardcoded.php.inc
This file contains 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,31 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture; | ||
|
||
class SubstrCompareNot | ||
{ | ||
public function run() | ||
{ | ||
$isNotMatch = substr_compare($haystack, 'needle', -6) != 0; | ||
|
||
$isNotMatch = 0 != substr_compare($haystack, 'needle', -6); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture; | ||
|
||
class SubstrCompareNot | ||
{ | ||
public function run() | ||
{ | ||
$isNotMatch = !str_ends_with($haystack, 'needle'); | ||
|
||
$isNotMatch = !str_ends_with($haystack, 'needle'); | ||
} | ||
} | ||
|
||
?> |
31 changes: 31 additions & 0 deletions
31
rules-tests/Php80/Rector/Identical/StrEndsWithRector/Fixture/substr_not_equal_prefix.php.inc
This file contains 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,31 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture; | ||
|
||
class SubstrNotPrefix | ||
{ | ||
public function run() | ||
{ | ||
$isNotMatch = substr($haystack, -strlen($needle)) != $needle; | ||
|
||
$isNotMatch = $needle != substr($haystack, -strlen($needle)); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture; | ||
|
||
class SubstrNotPrefix | ||
{ | ||
public function run() | ||
{ | ||
$isNotMatch = !str_ends_with($haystack, $needle); | ||
|
||
$isNotMatch = !str_ends_with($haystack, $needle); | ||
} | ||
} | ||
|
||
?> |
27 changes: 27 additions & 0 deletions
27
rules-tests/Php80/Rector/Identical/StrStartsWithRector/Fixture/fixture_equal.php.inc
This file contains 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,27 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Identical\StrStartsWithRector\Fixture; | ||
|
||
class Fixture | ||
{ | ||
public function run() | ||
{ | ||
$isMatch = substr($haystack, 0, strlen($needle)) == $needle; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Identical\StrStartsWithRector\Fixture; | ||
|
||
class Fixture | ||
{ | ||
public function run() | ||
{ | ||
$isMatch = str_starts_with($haystack, $needle); | ||
} | ||
} | ||
|
||
?> |
31 changes: 31 additions & 0 deletions
31
rules-tests/Php80/Rector/Identical/StrStartsWithRector/Fixture/hardcoded_equal.php.inc
This file contains 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,31 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Identical\StrStartsWithRector\Fixture; | ||
|
||
class HardCoded | ||
{ | ||
public function run() | ||
{ | ||
$isMatch = substr($haystack, 0, 3) == 'foo'; | ||
|
||
$isMatch = 'foo' == substr($haystack, 0, 3); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Identical\StrStartsWithRector\Fixture; | ||
|
||
class HardCoded | ||
{ | ||
public function run() | ||
{ | ||
$isMatch = str_starts_with($haystack, 'foo'); | ||
|
||
$isMatch = str_starts_with($haystack, 'foo'); | ||
} | ||
} | ||
|
||
?> |
31 changes: 31 additions & 0 deletions
31
rules-tests/Php80/Rector/Identical/StrStartsWithRector/Fixture/hardcoded_not_equal.php.inc
This file contains 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,31 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Identical\StrStartsWithRector\Fixture; | ||
|
||
class HardCodedNotIdentical | ||
{ | ||
public function run() | ||
{ | ||
$isMatch = substr($haystack, 0, 3) != 'foo'; | ||
|
||
$isMatch = 'foo' != substr($haystack, 0, 3); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Identical\StrStartsWithRector\Fixture; | ||
|
||
class HardCodedNotIdentical | ||
{ | ||
public function run() | ||
{ | ||
$isMatch = !str_starts_with($haystack, 'foo'); | ||
|
||
$isMatch = !str_starts_with($haystack, 'foo'); | ||
} | ||
} | ||
|
||
?> |
27 changes: 27 additions & 0 deletions
27
rules-tests/Php80/Rector/Identical/StrStartsWithRector/Fixture/not_equal_substr.php.inc
This file contains 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,27 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Identical\StrStartsWithRector\Fixture; | ||
|
||
class NotIdenticalSubstr | ||
{ | ||
public function run() | ||
{ | ||
$isNotMatch = substr($haystack, 0, strlen($needle)) != $needle; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Identical\StrStartsWithRector\Fixture; | ||
|
||
class NotIdenticalSubstr | ||
{ | ||
public function run() | ||
{ | ||
$isNotMatch = !str_starts_with($haystack, $needle); | ||
} | ||
} | ||
|
||
?> |
Oops, something went wrong.