-
Notifications
You must be signed in to change notification settings - Fork 26
DowngradeMbStrContainsRector #331
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
Changes from 4 commits
557b732
2402d39
8b15495
cdbbf49
6656092
081e073
06265a2
257f57a
1e18cd7
1e1806a
7bea52c
cdb3f07
046c1b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector; | ||
|
|
||
| use Iterator; | ||
| use PHPUnit\Framework\Attributes\DataProvider; | ||
| use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
|
||
| final class DowngradeMbStrContainsRectorTest extends AbstractRectorTestCase | ||
| { | ||
| #[DataProvider('provideData')] | ||
| public function test(string $filePath): void | ||
| { | ||
| $this->doTestFile($filePath); | ||
| } | ||
|
|
||
| public static function provideData(): Iterator | ||
| { | ||
| return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
| } | ||
|
|
||
| public function provideConfigFilePath(): string | ||
| { | ||
| return __DIR__ . '/config/configured_rule.php'; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture; | ||
|
|
||
| class Fixture | ||
| { | ||
| public function run() | ||
| { | ||
| $isMatch = str_contains('😊abc', 'a'); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am thinking if the strlen($needle) !== mb_strlen($needle)this, however, I prefer to not be part of downgrade php 8.0 set, as dealing with multibyte can be "there on purpose", user that needs exact change str_contains -> mb_strpos needs to enable manually as use and know the risk. |
||
| } | ||
| } | ||
|
|
||
| ?> | ||
| ----- | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture; | ||
|
|
||
| class Fixture | ||
| { | ||
| public function run() | ||
| { | ||
| $isMatch = mb_strpos('😊abc', 'a') !== false; | ||
| } | ||
| } | ||
|
|
||
| ?> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture; | ||
|
|
||
| class IdenticalStrpos | ||
| { | ||
| public function run() | ||
| { | ||
| $isMatch = !str_contains('abc😊', 'a'); | ||
| } | ||
| } | ||
|
|
||
| ?> | ||
| ----- | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture; | ||
|
|
||
| class IdenticalStrpos | ||
| { | ||
| public function run() | ||
| { | ||
| $isMatch = mb_strpos('abc😊', 'a') === false; | ||
| } | ||
| } | ||
|
|
||
| ?> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture; | ||
|
|
||
| class IdenticalStrstr | ||
| { | ||
| public function run() | ||
| { | ||
| $isMatch = !str_contains('abc', 'a'); | ||
| } | ||
| } | ||
|
|
||
| ?> | ||
| ----- | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture; | ||
|
|
||
| class IdenticalStrstr | ||
| { | ||
| public function run() | ||
| { | ||
| $isMatch = mb_strpos('abc', 'a') === false; | ||
| } | ||
| } | ||
|
|
||
| ?> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture; | ||
|
|
||
| final class NoStrContains | ||
| { | ||
| public function run() | ||
| { | ||
| return ! str_contains('abc', 'b'); | ||
| } | ||
| } | ||
|
|
||
| ?> | ||
| ----- | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture; | ||
|
|
||
| final class NoStrContains | ||
| { | ||
| public function run() | ||
| { | ||
| return mb_strpos('abc', 'b') === false; | ||
| } | ||
| } | ||
|
|
||
| ?> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture; | ||
|
|
||
| class IdenticalStrstr | ||
| { | ||
| public function run() | ||
| { | ||
| $isMatch = !str_contains('abc', 'a'); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these fixtures are invalid, as no multibyte in needle, only downgrade to mb_strpos when needle has multibyte char |
||
| } | ||
| } | ||
|
|
||
| ?> | ||
| ----- | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture; | ||
|
|
||
| class IdenticalStrstr | ||
| { | ||
| public function run() | ||
| { | ||
| $isMatch = mb_strpos('abc', 'a') === false; | ||
| } | ||
| } | ||
|
|
||
| ?> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture; | ||
|
|
||
| class OffsetStrpos | ||
| { | ||
| public function run() | ||
| { | ||
| $isMatch = str_contains(mb_substr('abc', 1), 'a'); | ||
| } | ||
| } | ||
| ?> | ||
| ----- | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture; | ||
|
|
||
| class OffsetStrpos | ||
| { | ||
| public function run() | ||
| { | ||
| $isMatch = mb_strpos('abc', 'a', 1) !== false; | ||
| } | ||
| } | ||
| ?> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture; | ||
|
|
||
| class OffsetExpressionStrpos | ||
| { | ||
| public function run() | ||
| { | ||
| $offset = 1; | ||
| $isMatch = str_contains(mb_substr('abc', $offset + 1), 'a'); | ||
| } | ||
| } | ||
| ?> | ||
| ----- | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture; | ||
|
|
||
| class OffsetExpressionStrpos | ||
| { | ||
| public function run() | ||
| { | ||
| $offset = 1; | ||
| $isMatch = mb_strpos('abc', 'a', $offset + 1) !== false; | ||
| } | ||
| } | ||
| ?> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture; | ||
|
|
||
| class OffsetExpressionStrpos | ||
| { | ||
| public function run() | ||
| { | ||
| $offset = 1; | ||
| $isMatch = str_contains(mb_substr('abc', $offset + 1), 'a'); | ||
| } | ||
| } | ||
| ?> | ||
| ----- | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture; | ||
|
|
||
| class OffsetExpressionStrpos | ||
| { | ||
| public function run() | ||
| { | ||
| $offset = 1; | ||
| $isMatch = mb_strpos('abc', 'a', $offset + 1) !== false; | ||
| } | ||
| } | ||
| ?> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture; | ||
|
|
||
| class OffsetNegativeStrpos | ||
| { | ||
| public function run() | ||
| { | ||
| $isMatch = str_contains(mb_substr('abc', -1), 'a'); | ||
| } | ||
| } | ||
| ?> | ||
| ----- | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture; | ||
|
|
||
| class OffsetNegativeStrpos | ||
| { | ||
| public function run() | ||
| { | ||
| $isMatch = mb_strpos('abc', 'a', -1) !== false; | ||
| } | ||
| } | ||
| ?> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture; | ||
|
|
||
| class OffsetNegativeStrpos | ||
| { | ||
| public function run() | ||
| { | ||
| $isMatch = str_contains(mb_substr('abc', -1), 'a'); | ||
| } | ||
| } | ||
| ?> | ||
| ----- | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture; | ||
|
|
||
| class OffsetNegativeStrpos | ||
| { | ||
| public function run() | ||
| { | ||
| $isMatch = mb_strpos('abc', 'a', -1) !== false; | ||
| } | ||
| } | ||
| ?> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture; | ||
|
|
||
| class OffsetStrpos | ||
| { | ||
| public function run() | ||
| { | ||
| $isMatch = str_contains(mb_substr('abc', 1), 'a'); | ||
| } | ||
| } | ||
| ?> | ||
| ----- | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture; | ||
|
|
||
| class OffsetStrpos | ||
| { | ||
| public function run() | ||
| { | ||
| $isMatch = mb_strpos('abc', 'a', 1) !== false; | ||
| } | ||
| } | ||
| ?> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture; | ||
|
|
||
| class OffsetVariableStrpos | ||
| { | ||
| public function run() | ||
| { | ||
| $offset = 1; | ||
| $isMatch = str_contains(mb_substr('abc', $offset), 'a'); | ||
| } | ||
| } | ||
| ?> | ||
| ----- | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture; | ||
|
|
||
| class OffsetVariableStrpos | ||
| { | ||
| public function run() | ||
| { | ||
| $offset = 1; | ||
| $isMatch = mb_strpos('abc', 'a', $offset) !== false; | ||
| } | ||
| } | ||
| ?> |
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.
unregister this, there is no
"mb_str_contains", onlystr_contains, that means that utilizestrposcan be on purpose.let user manually use if needed, dealing with user that may don't have mbstring extension or use strpos on purpose :)
user that use
mb_functions know why they are using themb_functions :)