From 557b73241ff265562aede06ebd7b17531004f439 Mon Sep 17 00:00:00 2001 From: Arshid Date: Wed, 17 Sep 2025 14:21:57 +0530 Subject: [PATCH 01/13] /DowngradeMbStrContainsRector --- .../DowngradeMbStrContainsRectorTest.php | 28 +++++ .../Fixture/not_str_contains.php.inc | 27 +++++ .../Fixture/str_contains.php.inc | 27 +++++ .../str_contains.php_with_mixed.php.inc | 29 +++++ .../config/configured_rule.php | 10 ++ .../FuncCall/DowngradeMbStrContainsRector.php | 103 ++++++++++++++++++ 6 files changed, 224 insertions(+) create mode 100644 rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/DowngradeMbStrContainsRectorTest.php create mode 100644 rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/not_str_contains.php.inc create mode 100644 rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/str_contains.php.inc create mode 100644 rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/str_contains.php_with_mixed.php.inc create mode 100644 rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/config/configured_rule.php create mode 100644 rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/DowngradeMbStrContainsRectorTest.php b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/DowngradeMbStrContainsRectorTest.php new file mode 100644 index 00000000..1ccea45d --- /dev/null +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/DowngradeMbStrContainsRectorTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/not_str_contains.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/not_str_contains.php.inc new file mode 100644 index 00000000..a1d502e2 --- /dev/null +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/not_str_contains.php.inc @@ -0,0 +1,27 @@ + +----- + diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/str_contains.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/str_contains.php.inc new file mode 100644 index 00000000..a240db65 --- /dev/null +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/str_contains.php.inc @@ -0,0 +1,27 @@ + +----- + diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/str_contains.php_with_mixed.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/str_contains.php_with_mixed.php.inc new file mode 100644 index 00000000..38797756 --- /dev/null +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/str_contains.php_with_mixed.php.inc @@ -0,0 +1,29 @@ + +----- + diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/config/configured_rule.php b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/config/configured_rule.php new file mode 100644 index 00000000..e654dc06 --- /dev/null +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(DowngradeMbStrContainsRector::class); +}; diff --git a/rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php b/rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php new file mode 100644 index 00000000..0aed1b2c --- /dev/null +++ b/rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php @@ -0,0 +1,103 @@ +> + */ + public function getNodeTypes(): array + { + return [FuncCall::class, BooleanNot::class]; + } + + /** + * @param FuncCall|BooleanNot $node + * @return Identical|NotIdentical|null The refactored node. + */ + public function refactor(Node $node): Identical | NotIdentical | null + { + $funcCall = $this->matchStrContainsOrNotStrContains($node); + + if (! $funcCall instanceof FuncCall) { + return null; + } + + $args = $funcCall->getArgs(); + if (count($args) < 2) { + return null; + } + + $haystack = $args[0]->value; + $needle = $args[1]->value; + + $funcCall = $this->nodeFactory->createFuncCall('mb_strpos', [$haystack, $needle]); + + if ($node instanceof BooleanNot) { + return new Identical($funcCall, $this->nodeFactory->createFalse()); + } + + return new NotIdentical($funcCall, $this->nodeFactory->createFalse()); + } + + private function matchStrContainsOrNotStrContains(FuncCall | BooleanNot $expr): ?FuncCall + { + $expr = ($expr instanceof BooleanNot) ? $expr->expr : $expr; + if (! $expr instanceof FuncCall) { + return null; + } + + if (! $this->isName($expr, 'str_contains')) { + return null; + } + + return $expr; + } +} From 2402d3976402d70ee974a21824c1cf4d41c3b71b Mon Sep 17 00:00:00 2001 From: Arshid Date: Wed, 17 Sep 2025 14:23:02 +0530 Subject: [PATCH 02/13] /DowngradeMbStrContainsRector --- config/set/downgrade-php80.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/set/downgrade-php80.php b/config/set/downgrade-php80.php index ce89592e..34b19dbc 100644 --- a/config/set/downgrade-php80.php +++ b/config/set/downgrade-php80.php @@ -19,6 +19,7 @@ use Rector\DowngradePhp80\Rector\Expression\DowngradeMatchToSwitchRector; use Rector\DowngradePhp80\Rector\Expression\DowngradeThrowExprRector; use Rector\DowngradePhp80\Rector\FuncCall\DowngradeArrayFilterNullableCallbackRector; +use Rector\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector; use Rector\DowngradePhp80\Rector\FuncCall\DowngradeNumberFormatNoFourthArgRector; use Rector\DowngradePhp80\Rector\FuncCall\DowngradeStrContainsRector; use Rector\DowngradePhp80\Rector\FuncCall\DowngradeStrEndsWithRector; @@ -70,6 +71,7 @@ DowngradePropertyPromotionRector::class, DowngradeNonCapturingCatchesRector::class, DowngradeStrContainsRector::class, + DowngradeMbStrContainsRector::class, DowngradeMatchToSwitchRector::class, DowngradeClassOnObjectToGetClassRector::class, DowngradeArbitraryExpressionsSupportRector::class, From 8b15495268be8edc86b408d6b6e2ec79a991f876 Mon Sep 17 00:00:00 2001 From: Arshid Date: Wed, 17 Sep 2025 20:26:57 +0530 Subject: [PATCH 03/13] /DowngradeMbStrContainsRector --- .../Fixture/fixture_equal.php.inc | 27 +++++++++++++++++++ .../Fixture/identical_mb_strpos.php.inc | 27 +++++++++++++++++++ .../Fixture/not_equal_mb_strstr.php.inc | 27 +++++++++++++++++++ .../Fixture/not_strstr.php.inc | 27 +++++++++++++++++++ .../Fixture/offset_equal_strpos.php.inc | 25 +++++++++++++++++ .../offset_expression_equal_strpos.php.inc | 27 +++++++++++++++++++ .../offset_expression_mb_strpos.php.inc | 27 +++++++++++++++++++ .../offset_negative_equal_strpos.php.inc | 25 +++++++++++++++++ .../Fixture/offset_negative_strpos.php.inc | 25 +++++++++++++++++ .../Fixture/offset_strpos.php.inc | 25 +++++++++++++++++ .../offset_variable_equal_strpos.php.inc | 27 +++++++++++++++++++ .../Fixture/offset_variable_strpos.php.inc | 27 +++++++++++++++++++ .../offset_variable_zero_equal_strpos.php.inc | 27 +++++++++++++++++++ .../offset_variable_zero_strpos.php.inc | 27 +++++++++++++++++++ .../Fixture/strstr.php.inc | 27 +++++++++++++++++++ .../Fixture/the_other_way.php.inc | 27 +++++++++++++++++++ .../Fixture/the_other_way_equal.php.inc | 27 +++++++++++++++++++ .../FuncCall/DowngradeMbStrContainsRector.php | 25 ++++++++++++++++- 18 files changed, 475 insertions(+), 1 deletion(-) create mode 100644 rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/fixture_equal.php.inc create mode 100644 rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/identical_mb_strpos.php.inc create mode 100644 rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/not_equal_mb_strstr.php.inc create mode 100644 rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/not_strstr.php.inc create mode 100644 rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_equal_strpos.php.inc create mode 100644 rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_expression_equal_strpos.php.inc create mode 100644 rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_expression_mb_strpos.php.inc create mode 100644 rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_negative_equal_strpos.php.inc create mode 100644 rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_negative_strpos.php.inc create mode 100644 rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_strpos.php.inc create mode 100644 rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_equal_strpos.php.inc create mode 100644 rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_strpos.php.inc create mode 100644 rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_zero_equal_strpos.php.inc create mode 100644 rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_zero_strpos.php.inc create mode 100644 rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/strstr.php.inc create mode 100644 rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/the_other_way.php.inc create mode 100644 rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/the_other_way_equal.php.inc diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/fixture_equal.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/fixture_equal.php.inc new file mode 100644 index 00000000..37b69fc0 --- /dev/null +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/fixture_equal.php.inc @@ -0,0 +1,27 @@ + +----- + \ No newline at end of file diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/identical_mb_strpos.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/identical_mb_strpos.php.inc new file mode 100644 index 00000000..1eb03f8a --- /dev/null +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/identical_mb_strpos.php.inc @@ -0,0 +1,27 @@ + +----- + \ No newline at end of file diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/not_equal_mb_strstr.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/not_equal_mb_strstr.php.inc new file mode 100644 index 00000000..02d222e6 --- /dev/null +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/not_equal_mb_strstr.php.inc @@ -0,0 +1,27 @@ + +----- + \ No newline at end of file diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/not_strstr.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/not_strstr.php.inc new file mode 100644 index 00000000..02d222e6 --- /dev/null +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/not_strstr.php.inc @@ -0,0 +1,27 @@ + +----- + \ No newline at end of file diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_equal_strpos.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_equal_strpos.php.inc new file mode 100644 index 00000000..262aa2c0 --- /dev/null +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_equal_strpos.php.inc @@ -0,0 +1,25 @@ + +----- + \ No newline at end of file diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_expression_equal_strpos.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_expression_equal_strpos.php.inc new file mode 100644 index 00000000..92f8e1ed --- /dev/null +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_expression_equal_strpos.php.inc @@ -0,0 +1,27 @@ + +----- + \ No newline at end of file diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_expression_mb_strpos.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_expression_mb_strpos.php.inc new file mode 100644 index 00000000..92f8e1ed --- /dev/null +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_expression_mb_strpos.php.inc @@ -0,0 +1,27 @@ + +----- + \ No newline at end of file diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_negative_equal_strpos.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_negative_equal_strpos.php.inc new file mode 100644 index 00000000..ce0c2637 --- /dev/null +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_negative_equal_strpos.php.inc @@ -0,0 +1,25 @@ + +----- + \ No newline at end of file diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_negative_strpos.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_negative_strpos.php.inc new file mode 100644 index 00000000..ce0c2637 --- /dev/null +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_negative_strpos.php.inc @@ -0,0 +1,25 @@ + +----- + \ No newline at end of file diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_strpos.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_strpos.php.inc new file mode 100644 index 00000000..262aa2c0 --- /dev/null +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_strpos.php.inc @@ -0,0 +1,25 @@ + +----- + \ No newline at end of file diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_equal_strpos.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_equal_strpos.php.inc new file mode 100644 index 00000000..2cf0080f --- /dev/null +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_equal_strpos.php.inc @@ -0,0 +1,27 @@ + +----- + \ No newline at end of file diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_strpos.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_strpos.php.inc new file mode 100644 index 00000000..7e69a0ee --- /dev/null +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_strpos.php.inc @@ -0,0 +1,27 @@ + +----- + diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_zero_equal_strpos.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_zero_equal_strpos.php.inc new file mode 100644 index 00000000..04cdfdcc --- /dev/null +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_zero_equal_strpos.php.inc @@ -0,0 +1,27 @@ + +----- + \ No newline at end of file diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_zero_strpos.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_zero_strpos.php.inc new file mode 100644 index 00000000..04cdfdcc --- /dev/null +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_zero_strpos.php.inc @@ -0,0 +1,27 @@ + +----- + \ No newline at end of file diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/strstr.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/strstr.php.inc new file mode 100644 index 00000000..ef9d4445 --- /dev/null +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/strstr.php.inc @@ -0,0 +1,27 @@ + +----- + diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/the_other_way.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/the_other_way.php.inc new file mode 100644 index 00000000..7a60ab6e --- /dev/null +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/the_other_way.php.inc @@ -0,0 +1,27 @@ + +----- + \ No newline at end of file diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/the_other_way_equal.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/the_other_way_equal.php.inc new file mode 100644 index 00000000..bef5773f --- /dev/null +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/the_other_way_equal.php.inc @@ -0,0 +1,27 @@ + +----- + diff --git a/rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php b/rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php index 0aed1b2c..439b6ea4 100644 --- a/rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php +++ b/rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php @@ -5,6 +5,7 @@ namespace Rector\DowngradePhp80\Rector\FuncCall; use PhpParser\Node; +use PhpParser\Node\Arg; use PhpParser\Node\Expr\BinaryOp\Identical; use PhpParser\Node\Expr\BinaryOp\NotIdentical; use PhpParser\Node\Expr\BooleanNot; @@ -77,8 +78,30 @@ public function refactor(Node $node): Identical | NotIdentical | null $haystack = $args[0]->value; $needle = $args[1]->value; + $offset = null; - $funcCall = $this->nodeFactory->createFuncCall('mb_strpos', [$haystack, $needle]); + if($haystack instanceof FuncCall){ + if(!$this->isName($haystack->name, 'mb_substr')){ + return null; + } + $substrArg = $haystack->getArgs(); + if(isset($substrArg[0]) && !$substrArg[0] instanceof Arg){ + return null; + } + if(isset($substrArg[1]) && !$substrArg[1] instanceof Arg){ + return null; + } + $haystack = $substrArg[0]; + $offset = $substrArg[1]; + } + + if($offset instanceof Arg){ + $funcCall = $this->nodeFactory->createFuncCall('mb_strpos', [$haystack, $needle, $offset]); + } + + if(!$offset instanceof Arg){ + $funcCall = $this->nodeFactory->createFuncCall('mb_strpos', [$haystack, $needle]); + } if ($node instanceof BooleanNot) { return new Identical($funcCall, $this->nodeFactory->createFalse()); From cdbbf49375309fbd7d46c5077701eb3393db8854 Mon Sep 17 00:00:00 2001 From: Arshid Date: Wed, 17 Sep 2025 20:31:21 +0530 Subject: [PATCH 04/13] /DowngradeMbStrContainsRector --- .../FuncCall/DowngradeMbStrContainsRector.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php b/rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php index 439b6ea4..e0c652a2 100644 --- a/rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php +++ b/rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php @@ -80,26 +80,26 @@ public function refactor(Node $node): Identical | NotIdentical | null $needle = $args[1]->value; $offset = null; - if($haystack instanceof FuncCall){ - if(!$this->isName($haystack->name, 'mb_substr')){ + if ($haystack instanceof FuncCall) { + if (! $this->isName($haystack->name, 'mb_substr')) { return null; } $substrArg = $haystack->getArgs(); - if(isset($substrArg[0]) && !$substrArg[0] instanceof Arg){ + if (isset($substrArg[0]) && ! $substrArg[0] instanceof Arg) { return null; } - if(isset($substrArg[1]) && !$substrArg[1] instanceof Arg){ + if (isset($substrArg[1]) && ! $substrArg[1] instanceof Arg) { return null; } $haystack = $substrArg[0]; $offset = $substrArg[1]; } - if($offset instanceof Arg){ + if ($offset instanceof Arg) { $funcCall = $this->nodeFactory->createFuncCall('mb_strpos', [$haystack, $needle, $offset]); } - - if(!$offset instanceof Arg){ + + if (! $offset instanceof Arg) { $funcCall = $this->nodeFactory->createFuncCall('mb_strpos', [$haystack, $needle]); } From 66560926d5e8a9061adf245df200f1aee393f4d2 Mon Sep 17 00:00:00 2001 From: Arshid Date: Wed, 17 Sep 2025 21:02:13 +0530 Subject: [PATCH 05/13] /DowngradeMbStrContainsRector --- .../Fixture/fixture_equal.php.inc | 4 +-- .../Fixture/identical_mb_strpos.php.inc | 4 +-- .../Fixture/not_equal_mb_strstr.php.inc | 4 +-- .../Fixture/not_str_contains.php.inc | 4 +-- .../Fixture/not_strstr.php.inc | 4 +-- .../Fixture/offset_equal_strpos.php.inc | 4 +-- .../offset_expression_equal_strpos.php.inc | 4 +-- .../offset_expression_mb_strpos.php.inc | 4 +-- .../offset_negative_equal_strpos.php.inc | 4 +-- .../Fixture/offset_negative_strpos.php.inc | 4 +-- .../Fixture/offset_strpos.php.inc | 4 +-- .../offset_variable_equal_strpos.php.inc | 4 +-- .../Fixture/offset_variable_strpos.php.inc | 4 +-- .../offset_variable_zero_equal_strpos.php.inc | 4 +-- .../offset_variable_zero_strpos.php.inc | 4 +-- .../Fixture/skip_str_contains.php.inc | 13 +++++++++ .../skip_str_contains.php_with_mixed.php.inc | 14 +++++++++ .../Fixture/str_contains.php.inc | 27 ----------------- .../str_contains.php_with_mixed.php.inc | 29 ------------------- .../Fixture/strstr.php.inc | 4 +-- .../Fixture/the_other_way.php.inc | 4 +-- .../Fixture/the_other_way_equal.php.inc | 4 +-- .../FuncCall/DowngradeMbStrContainsRector.php | 14 +++++++-- 23 files changed, 75 insertions(+), 94 deletions(-) create mode 100644 rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/skip_str_contains.php.inc create mode 100644 rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/skip_str_contains.php_with_mixed.php.inc delete mode 100644 rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/str_contains.php.inc delete mode 100644 rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/str_contains.php_with_mixed.php.inc diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/fixture_equal.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/fixture_equal.php.inc index 37b69fc0..3f4802c6 100644 --- a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/fixture_equal.php.inc +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/fixture_equal.php.inc @@ -6,7 +6,7 @@ class Fixture { public function run() { - $isMatch = str_contains('😊abc', 'a'); + $isMatch = str_contains('😊abc', '😊a'); } } @@ -20,7 +20,7 @@ class Fixture { public function run() { - $isMatch = mb_strpos('😊abc', 'a') !== false; + $isMatch = mb_strpos('😊abc', '😊a') !== false; } } diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/identical_mb_strpos.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/identical_mb_strpos.php.inc index 1eb03f8a..2d7e7f7a 100644 --- a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/identical_mb_strpos.php.inc +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/identical_mb_strpos.php.inc @@ -6,7 +6,7 @@ class IdenticalStrpos { public function run() { - $isMatch = !str_contains('abc😊', 'a'); + $isMatch = !str_contains('abc😊', '😊a'); } } @@ -20,7 +20,7 @@ class IdenticalStrpos { public function run() { - $isMatch = mb_strpos('abc😊', 'a') === false; + $isMatch = mb_strpos('abc😊', '😊a') === false; } } diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/not_equal_mb_strstr.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/not_equal_mb_strstr.php.inc index 02d222e6..8213fa94 100644 --- a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/not_equal_mb_strstr.php.inc +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/not_equal_mb_strstr.php.inc @@ -6,7 +6,7 @@ class IdenticalStrstr { public function run() { - $isMatch = !str_contains('abc', 'a'); + $isMatch = !str_contains('😊abc', '😊a'); } } @@ -20,7 +20,7 @@ class IdenticalStrstr { public function run() { - $isMatch = mb_strpos('abc', 'a') === false; + $isMatch = mb_strpos('😊abc', '😊a') === false; } } diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/not_str_contains.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/not_str_contains.php.inc index a1d502e2..cd27a020 100644 --- a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/not_str_contains.php.inc +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/not_str_contains.php.inc @@ -6,7 +6,7 @@ final class NoStrContains { public function run() { - return ! str_contains('abc', 'b'); + return ! str_contains('😊abc', 'b😊'); } } @@ -20,7 +20,7 @@ final class NoStrContains { public function run() { - return mb_strpos('abc', 'b') === false; + return mb_strpos('😊abc', 'b😊') === false; } } diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/not_strstr.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/not_strstr.php.inc index 02d222e6..8213fa94 100644 --- a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/not_strstr.php.inc +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/not_strstr.php.inc @@ -6,7 +6,7 @@ class IdenticalStrstr { public function run() { - $isMatch = !str_contains('abc', 'a'); + $isMatch = !str_contains('😊abc', '😊a'); } } @@ -20,7 +20,7 @@ class IdenticalStrstr { public function run() { - $isMatch = mb_strpos('abc', 'a') === false; + $isMatch = mb_strpos('😊abc', '😊a') === false; } } diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_equal_strpos.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_equal_strpos.php.inc index 262aa2c0..f3966775 100644 --- a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_equal_strpos.php.inc +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_equal_strpos.php.inc @@ -6,7 +6,7 @@ class OffsetStrpos { public function run() { - $isMatch = str_contains(mb_substr('abc', 1), 'a'); + $isMatch = str_contains(mb_substr('😊abc', 1), '😊a'); } } ?> @@ -19,7 +19,7 @@ class OffsetStrpos { public function run() { - $isMatch = mb_strpos('abc', 'a', 1) !== false; + $isMatch = mb_strpos('😊abc', '😊a', 1) !== false; } } ?> \ No newline at end of file diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_expression_equal_strpos.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_expression_equal_strpos.php.inc index 92f8e1ed..c9171ca8 100644 --- a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_expression_equal_strpos.php.inc +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_expression_equal_strpos.php.inc @@ -7,7 +7,7 @@ class OffsetExpressionStrpos public function run() { $offset = 1; - $isMatch = str_contains(mb_substr('abc', $offset + 1), 'a'); + $isMatch = str_contains(mb_substr('😊abc', $offset + 1), '😊a'); } } ?> @@ -21,7 +21,7 @@ class OffsetExpressionStrpos public function run() { $offset = 1; - $isMatch = mb_strpos('abc', 'a', $offset + 1) !== false; + $isMatch = mb_strpos('😊abc', '😊a', $offset + 1) !== false; } } ?> \ No newline at end of file diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_expression_mb_strpos.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_expression_mb_strpos.php.inc index 92f8e1ed..c9171ca8 100644 --- a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_expression_mb_strpos.php.inc +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_expression_mb_strpos.php.inc @@ -7,7 +7,7 @@ class OffsetExpressionStrpos public function run() { $offset = 1; - $isMatch = str_contains(mb_substr('abc', $offset + 1), 'a'); + $isMatch = str_contains(mb_substr('😊abc', $offset + 1), '😊a'); } } ?> @@ -21,7 +21,7 @@ class OffsetExpressionStrpos public function run() { $offset = 1; - $isMatch = mb_strpos('abc', 'a', $offset + 1) !== false; + $isMatch = mb_strpos('😊abc', '😊a', $offset + 1) !== false; } } ?> \ No newline at end of file diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_negative_equal_strpos.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_negative_equal_strpos.php.inc index ce0c2637..ce04ca76 100644 --- a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_negative_equal_strpos.php.inc +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_negative_equal_strpos.php.inc @@ -6,7 +6,7 @@ class OffsetNegativeStrpos { public function run() { - $isMatch = str_contains(mb_substr('abc', -1), 'a'); + $isMatch = str_contains(mb_substr('😊abc', -1), '😊a'); } } ?> @@ -19,7 +19,7 @@ class OffsetNegativeStrpos { public function run() { - $isMatch = mb_strpos('abc', 'a', -1) !== false; + $isMatch = mb_strpos('😊abc', '😊a', -1) !== false; } } ?> \ No newline at end of file diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_negative_strpos.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_negative_strpos.php.inc index ce0c2637..ce04ca76 100644 --- a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_negative_strpos.php.inc +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_negative_strpos.php.inc @@ -6,7 +6,7 @@ class OffsetNegativeStrpos { public function run() { - $isMatch = str_contains(mb_substr('abc', -1), 'a'); + $isMatch = str_contains(mb_substr('😊abc', -1), '😊a'); } } ?> @@ -19,7 +19,7 @@ class OffsetNegativeStrpos { public function run() { - $isMatch = mb_strpos('abc', 'a', -1) !== false; + $isMatch = mb_strpos('😊abc', '😊a', -1) !== false; } } ?> \ No newline at end of file diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_strpos.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_strpos.php.inc index 262aa2c0..f3966775 100644 --- a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_strpos.php.inc +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_strpos.php.inc @@ -6,7 +6,7 @@ class OffsetStrpos { public function run() { - $isMatch = str_contains(mb_substr('abc', 1), 'a'); + $isMatch = str_contains(mb_substr('😊abc', 1), '😊a'); } } ?> @@ -19,7 +19,7 @@ class OffsetStrpos { public function run() { - $isMatch = mb_strpos('abc', 'a', 1) !== false; + $isMatch = mb_strpos('😊abc', '😊a', 1) !== false; } } ?> \ No newline at end of file diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_equal_strpos.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_equal_strpos.php.inc index 2cf0080f..6583f2a1 100644 --- a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_equal_strpos.php.inc +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_equal_strpos.php.inc @@ -7,7 +7,7 @@ class OffsetVariableStrpos public function run() { $offset = 1; - $isMatch = str_contains(mb_substr('abc', $offset), 'a'); + $isMatch = str_contains(mb_substr('😊abc', $offset), '😊a'); } } ?> @@ -21,7 +21,7 @@ class OffsetVariableStrpos public function run() { $offset = 1; - $isMatch = mb_strpos('abc', 'a', $offset) !== false; + $isMatch = mb_strpos('😊abc', '😊a', $offset) !== false; } } ?> \ No newline at end of file diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_strpos.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_strpos.php.inc index 7e69a0ee..61af025a 100644 --- a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_strpos.php.inc +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_strpos.php.inc @@ -7,7 +7,7 @@ class OffsetVariableStrpos public function run() { $offset = 1; - $isMatch = str_contains(mb_substr('abc', $offset), 'a'); + $isMatch = str_contains(mb_substr('😊abc', $offset), '😊a'); } } ?> @@ -21,7 +21,7 @@ class OffsetVariableStrpos public function run() { $offset = 1; - $isMatch = mb_strpos('abc', 'a', $offset) !== false; + $isMatch = mb_strpos('😊abc', '😊a', $offset) !== false; } } ?> diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_zero_equal_strpos.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_zero_equal_strpos.php.inc index 04cdfdcc..85374622 100644 --- a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_zero_equal_strpos.php.inc +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_zero_equal_strpos.php.inc @@ -7,7 +7,7 @@ class OffsetVariableZeroStrpos public function run() { $offset = 0; - $isMatch = str_contains(mb_substr('abc', $offset), 'a'); + $isMatch = str_contains(mb_substr('😊abc', $offset), '😊a'); } } ?> @@ -21,7 +21,7 @@ class OffsetVariableZeroStrpos public function run() { $offset = 0; - $isMatch = mb_strpos('abc', 'a', $offset) !== false; + $isMatch = mb_strpos('😊abc', '😊a', $offset) !== false; } } ?> \ No newline at end of file diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_zero_strpos.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_zero_strpos.php.inc index 04cdfdcc..85374622 100644 --- a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_zero_strpos.php.inc +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_zero_strpos.php.inc @@ -7,7 +7,7 @@ class OffsetVariableZeroStrpos public function run() { $offset = 0; - $isMatch = str_contains(mb_substr('abc', $offset), 'a'); + $isMatch = str_contains(mb_substr('😊abc', $offset), '😊a'); } } ?> @@ -21,7 +21,7 @@ class OffsetVariableZeroStrpos public function run() { $offset = 0; - $isMatch = mb_strpos('abc', 'a', $offset) !== false; + $isMatch = mb_strpos('😊abc', '😊a', $offset) !== false; } } ?> \ No newline at end of file diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/skip_str_contains.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/skip_str_contains.php.inc new file mode 100644 index 00000000..8b079498 --- /dev/null +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/skip_str_contains.php.inc @@ -0,0 +1,13 @@ + diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/skip_str_contains.php_with_mixed.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/skip_str_contains.php_with_mixed.php.inc new file mode 100644 index 00000000..ee4790e8 --- /dev/null +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/skip_str_contains.php_with_mixed.php.inc @@ -0,0 +1,14 @@ + diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/str_contains.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/str_contains.php.inc deleted file mode 100644 index a240db65..00000000 --- a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/str_contains.php.inc +++ /dev/null @@ -1,27 +0,0 @@ - ------ - diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/str_contains.php_with_mixed.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/str_contains.php_with_mixed.php.inc deleted file mode 100644 index 38797756..00000000 --- a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/str_contains.php_with_mixed.php.inc +++ /dev/null @@ -1,29 +0,0 @@ - ------ - diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/strstr.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/strstr.php.inc index ef9d4445..010e047b 100644 --- a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/strstr.php.inc +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/strstr.php.inc @@ -6,7 +6,7 @@ class Strstr { public function run() { - $isMatch = str_contains('abc', 'a'); + $isMatch = str_contains('😊abc', '😊a'); } } @@ -20,7 +20,7 @@ class Strstr { public function run() { - $isMatch = mb_strpos('abc', 'a') !== false; + $isMatch = mb_strpos('😊abc', '😊a') !== false; } } diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/the_other_way.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/the_other_way.php.inc index 7a60ab6e..43407571 100644 --- a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/the_other_way.php.inc +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/the_other_way.php.inc @@ -6,7 +6,7 @@ class TheOtherWay { public function run() { - $isMatch = str_contains('abc', 'a'); + $isMatch = str_contains('😊abc', '😊a'); } } @@ -20,7 +20,7 @@ class TheOtherWay { public function run() { - $isMatch = mb_strpos('abc', 'a') !== false; + $isMatch = mb_strpos('😊abc', '😊a') !== false; } } diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/the_other_way_equal.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/the_other_way_equal.php.inc index bef5773f..08c43496 100644 --- a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/the_other_way_equal.php.inc +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/the_other_way_equal.php.inc @@ -6,7 +6,7 @@ class TheOtherWay { public function run() { - $isMatch = str_contains('abc', 'a'); + $isMatch = str_contains('😊abc', '😊a'); } } @@ -20,7 +20,7 @@ class TheOtherWay { public function run() { - $isMatch = mb_strpos('abc', 'a') !== false; + $isMatch = mb_strpos('😊abc', '😊a') !== false; } } diff --git a/rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php b/rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php index e0c652a2..c7af93b7 100644 --- a/rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php +++ b/rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php @@ -9,6 +9,7 @@ use PhpParser\Node\Expr\BinaryOp\Identical; use PhpParser\Node\Expr\BinaryOp\NotIdentical; use PhpParser\Node\Expr\BooleanNot; +use PhpParser\Node\Scalar\String_; use PhpParser\Node\Expr\FuncCall; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -32,7 +33,7 @@ class SomeClass { public function run() { - return str_contains('abc', 'a'); + return str_contains('😊abc', '😊a'); } } CODE_SAMPLE @@ -42,7 +43,7 @@ class SomeClass { public function run() { - return mb_strpos('abc', 'a') !== false; + return mb_strpos('😊abc', '😊a') !== false; } } CODE_SAMPLE @@ -84,6 +85,7 @@ public function refactor(Node $node): Identical | NotIdentical | null if (! $this->isName($haystack->name, 'mb_substr')) { return null; } + $substrArg = $haystack->getArgs(); if (isset($substrArg[0]) && ! $substrArg[0] instanceof Arg) { return null; @@ -95,6 +97,14 @@ public function refactor(Node $node): Identical | NotIdentical | null $offset = $substrArg[1]; } + if (!$needle instanceof String_) { + return null; + } + + if(strlen($needle->value) === mb_strlen($needle->value)){ + return null; + } + if ($offset instanceof Arg) { $funcCall = $this->nodeFactory->createFuncCall('mb_strpos', [$haystack, $needle, $offset]); } From 081e0739db1ae6b6a88cdd793dc4d2334d4ba5f6 Mon Sep 17 00:00:00 2001 From: Arshid Date: Wed, 17 Sep 2025 21:03:22 +0530 Subject: [PATCH 06/13] DowngradeMbStrContainsRector --- config/set/downgrade-php80.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/config/set/downgrade-php80.php b/config/set/downgrade-php80.php index 34b19dbc..ce89592e 100644 --- a/config/set/downgrade-php80.php +++ b/config/set/downgrade-php80.php @@ -19,7 +19,6 @@ use Rector\DowngradePhp80\Rector\Expression\DowngradeMatchToSwitchRector; use Rector\DowngradePhp80\Rector\Expression\DowngradeThrowExprRector; use Rector\DowngradePhp80\Rector\FuncCall\DowngradeArrayFilterNullableCallbackRector; -use Rector\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector; use Rector\DowngradePhp80\Rector\FuncCall\DowngradeNumberFormatNoFourthArgRector; use Rector\DowngradePhp80\Rector\FuncCall\DowngradeStrContainsRector; use Rector\DowngradePhp80\Rector\FuncCall\DowngradeStrEndsWithRector; @@ -71,7 +70,6 @@ DowngradePropertyPromotionRector::class, DowngradeNonCapturingCatchesRector::class, DowngradeStrContainsRector::class, - DowngradeMbStrContainsRector::class, DowngradeMatchToSwitchRector::class, DowngradeClassOnObjectToGetClassRector::class, DowngradeArbitraryExpressionsSupportRector::class, From 06265a2c733a5254a8bbaf26274978fb1407458d Mon Sep 17 00:00:00 2001 From: Arshid Date: Wed, 17 Sep 2025 21:12:09 +0530 Subject: [PATCH 07/13] DowngradeMbStrContainsRector --- .../Rector/FuncCall/DowngradeMbStrContainsRector.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php b/rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php index c7af93b7..9f01c929 100644 --- a/rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php +++ b/rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php @@ -68,6 +68,10 @@ public function refactor(Node $node): Identical | NotIdentical | null { $funcCall = $this->matchStrContainsOrNotStrContains($node); + if ($funcCall->isFirstClassCallable()) { + return null; + } + if (! $funcCall instanceof FuncCall) { return null; } From 257f57a560e4cbd235a0b4b83aa218ef507ae047 Mon Sep 17 00:00:00 2001 From: Arshid Date: Wed, 17 Sep 2025 21:16:43 +0530 Subject: [PATCH 08/13] DowngradeMbStrContainsRector --- .../Fixture/skip_fixture_equal.php.inc | 13 +++++++++++++ .../FuncCall/DowngradeMbStrContainsRector.php | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/skip_fixture_equal.php.inc diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/skip_fixture_equal.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/skip_fixture_equal.php.inc new file mode 100644 index 00000000..bd59bc8f --- /dev/null +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/skip_fixture_equal.php.inc @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php b/rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php index 9f01c929..adeec78f 100644 --- a/rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php +++ b/rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php @@ -68,7 +68,7 @@ public function refactor(Node $node): Identical | NotIdentical | null { $funcCall = $this->matchStrContainsOrNotStrContains($node); - if ($funcCall->isFirstClassCallable()) { + if (!$funcCall->isFirstClassCallable()) { return null; } From 1e18cd7ba4ea1e25220135fbacd09325be79db06 Mon Sep 17 00:00:00 2001 From: Arshid Date: Wed, 17 Sep 2025 21:19:30 +0530 Subject: [PATCH 09/13] DowngradeMbStrContainsRector --- .../Rector/FuncCall/DowngradeMbStrContainsRector.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php b/rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php index adeec78f..824b1513 100644 --- a/rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php +++ b/rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php @@ -68,11 +68,11 @@ public function refactor(Node $node): Identical | NotIdentical | null { $funcCall = $this->matchStrContainsOrNotStrContains($node); - if (!$funcCall->isFirstClassCallable()) { + if (! $funcCall instanceof FuncCall) { return null; } - if (! $funcCall instanceof FuncCall) { + if ($funcCall->isFirstClassCallable()) { return null; } From 1e1806ad38ef6e724ac03e496c2bba7b361d5df1 Mon Sep 17 00:00:00 2001 From: Arshid Date: Thu, 18 Sep 2025 07:11:43 +0530 Subject: [PATCH 10/13] DowngradeMbStrContainsRector --- .../DowngradeMbStrContainsRectorTest.php | 4 ++-- .../Fixture/fixture_equal.php.inc | 4 ++-- .../Fixture/identical_mb_strpos.php.inc | 4 ++-- .../Fixture/not_equal_mb_strstr.php.inc | 4 ++-- .../Fixture/not_str_contains.php.inc | 4 ++-- .../Fixture/not_strstr.php.inc | 4 ++-- .../Fixture/offset_equal_strpos.php.inc | 4 ++-- .../Fixture/offset_expression_equal_strpos.php.inc | 4 ++-- .../Fixture/offset_expression_mb_strpos.php.inc | 4 ++-- .../Fixture/offset_negative_equal_strpos.php.inc | 4 ++-- .../Fixture/offset_negative_strpos.php.inc | 4 ++-- .../Fixture/offset_strpos.php.inc | 4 ++-- .../Fixture/offset_variable_equal_strpos.php.inc | 4 ++-- .../Fixture/offset_variable_strpos.php.inc | 4 ++-- .../Fixture/offset_variable_zero_equal_strpos.php.inc | 4 ++-- .../Fixture/offset_variable_zero_strpos.php.inc | 4 ++-- .../Fixture/skip_fixture_equal.php.inc | 2 +- .../Fixture/skip_str_contains.php.inc | 2 +- .../Fixture/skip_str_contains.php_with_mixed.php.inc | 2 +- .../DowngradeMbStrContainsRector/Fixture/strstr.php.inc | 4 ++-- .../Fixture/the_other_way.php.inc | 4 ++-- .../Fixture/the_other_way_equal.php.inc | 4 ++-- .../config/configured_rule.php | 4 ++-- .../Rector/FuncCall/DowngradeMbStrContainsRector.php | 9 +++++++-- 24 files changed, 50 insertions(+), 45 deletions(-) diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/DowngradeMbStrContainsRectorTest.php b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/DowngradeMbStrContainsRectorTest.php index 1ccea45d..de0c2219 100644 --- a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/DowngradeMbStrContainsRectorTest.php +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/DowngradeMbStrContainsRectorTest.php @@ -2,13 +2,13 @@ declare(strict_types=1); -namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector; +namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeStrContainsWithMultibyteNeedleRector; use Iterator; use PHPUnit\Framework\Attributes\DataProvider; use Rector\Testing\PHPUnit\AbstractRectorTestCase; -final class DowngradeMbStrContainsRectorTest extends AbstractRectorTestCase +final class DowngradeStrContainsWithMultibyteNeedleRectorTest extends AbstractRectorTestCase { #[DataProvider('provideData')] public function test(string $filePath): void diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/fixture_equal.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/fixture_equal.php.inc index 3f4802c6..c120cd9a 100644 --- a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/fixture_equal.php.inc +++ b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/fixture_equal.php.inc @@ -1,6 +1,6 @@ rule(DowngradeMbStrContainsRector::class); + $rectorConfig->rule(DowngradeStrContainsWithMultibyteNeedleRector::class); }; diff --git a/rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php b/rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php index 824b1513..b2916de2 100644 --- a/rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php +++ b/rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php @@ -18,9 +18,9 @@ /** * @changelog https://wiki.php.net/rfc/str_contains * - * @see \Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\DowngradeMbStrContainsRectorTest + * @see \Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeStrContainsWithMultibyteNeedleRector\DowngradeStrContainsWithMultibyteNeedleRectorTest */ -final class DowngradeMbStrContainsRector extends AbstractRector +final class DowngradeStrContainsWithMultibyteNeedleRector extends AbstractRector { public function getRuleDefinition(): RuleDefinition { @@ -86,10 +86,15 @@ public function refactor(Node $node): Identical | NotIdentical | null $offset = null; if ($haystack instanceof FuncCall) { + if (! $this->isName($haystack->name, 'mb_substr')) { return null; } + if ($haystack->isFirstClassCallable()) { + return null; + } + $substrArg = $haystack->getArgs(); if (isset($substrArg[0]) && ! $substrArg[0] instanceof Arg) { return null; From 7bea52c20d4596e5b70f3551f30815d771d89957 Mon Sep 17 00:00:00 2001 From: Arshid Date: Thu, 18 Sep 2025 07:15:26 +0530 Subject: [PATCH 11/13] DowngradeMbStrContainsRector --- .../DowngradeStrContainsWithMultibyteNeedleRectorTest.php} | 0 .../Fixture/fixture_equal.php.inc | 0 .../Fixture/identical_mb_strpos.php.inc | 0 .../Fixture/not_equal_mb_strstr.php.inc | 0 .../Fixture/not_str_contains.php.inc | 0 .../Fixture/not_strstr.php.inc | 0 .../Fixture/offset_equal_strpos.php.inc | 0 .../Fixture/offset_expression_equal_strpos.php.inc | 0 .../Fixture/offset_expression_mb_strpos.php.inc | 0 .../Fixture/offset_negative_equal_strpos.php.inc | 0 .../Fixture/offset_negative_strpos.php.inc | 0 .../Fixture/offset_strpos.php.inc | 0 .../Fixture/offset_variable_equal_strpos.php.inc | 0 .../Fixture/offset_variable_strpos.php.inc | 0 .../Fixture/offset_variable_zero_equal_strpos.php.inc | 0 .../Fixture/offset_variable_zero_strpos.php.inc | 0 .../Fixture/skip_fixture_equal.php.inc | 0 .../Fixture/skip_str_contains.php.inc | 0 .../Fixture/skip_str_contains.php_with_mixed.php.inc | 0 .../Fixture/strstr.php.inc | 0 .../Fixture/the_other_way.php.inc | 0 .../Fixture/the_other_way_equal.php.inc | 0 .../config/configured_rule.php | 0 23 files changed, 0 insertions(+), 0 deletions(-) rename rules-tests/DowngradePhp80/Rector/FuncCall/{DowngradeMbStrContainsRector/DowngradeMbStrContainsRectorTest.php => DowngradeStrContainsWithMultibyteNeedleRector/DowngradeStrContainsWithMultibyteNeedleRectorTest.php} (100%) rename rules-tests/DowngradePhp80/Rector/FuncCall/{DowngradeMbStrContainsRector => DowngradeStrContainsWithMultibyteNeedleRector}/Fixture/fixture_equal.php.inc (100%) rename rules-tests/DowngradePhp80/Rector/FuncCall/{DowngradeMbStrContainsRector => DowngradeStrContainsWithMultibyteNeedleRector}/Fixture/identical_mb_strpos.php.inc (100%) rename rules-tests/DowngradePhp80/Rector/FuncCall/{DowngradeMbStrContainsRector => DowngradeStrContainsWithMultibyteNeedleRector}/Fixture/not_equal_mb_strstr.php.inc (100%) rename rules-tests/DowngradePhp80/Rector/FuncCall/{DowngradeMbStrContainsRector => DowngradeStrContainsWithMultibyteNeedleRector}/Fixture/not_str_contains.php.inc (100%) rename rules-tests/DowngradePhp80/Rector/FuncCall/{DowngradeMbStrContainsRector => DowngradeStrContainsWithMultibyteNeedleRector}/Fixture/not_strstr.php.inc (100%) rename rules-tests/DowngradePhp80/Rector/FuncCall/{DowngradeMbStrContainsRector => DowngradeStrContainsWithMultibyteNeedleRector}/Fixture/offset_equal_strpos.php.inc (100%) rename rules-tests/DowngradePhp80/Rector/FuncCall/{DowngradeMbStrContainsRector => DowngradeStrContainsWithMultibyteNeedleRector}/Fixture/offset_expression_equal_strpos.php.inc (100%) rename rules-tests/DowngradePhp80/Rector/FuncCall/{DowngradeMbStrContainsRector => DowngradeStrContainsWithMultibyteNeedleRector}/Fixture/offset_expression_mb_strpos.php.inc (100%) rename rules-tests/DowngradePhp80/Rector/FuncCall/{DowngradeMbStrContainsRector => DowngradeStrContainsWithMultibyteNeedleRector}/Fixture/offset_negative_equal_strpos.php.inc (100%) rename rules-tests/DowngradePhp80/Rector/FuncCall/{DowngradeMbStrContainsRector => DowngradeStrContainsWithMultibyteNeedleRector}/Fixture/offset_negative_strpos.php.inc (100%) rename rules-tests/DowngradePhp80/Rector/FuncCall/{DowngradeMbStrContainsRector => DowngradeStrContainsWithMultibyteNeedleRector}/Fixture/offset_strpos.php.inc (100%) rename rules-tests/DowngradePhp80/Rector/FuncCall/{DowngradeMbStrContainsRector => DowngradeStrContainsWithMultibyteNeedleRector}/Fixture/offset_variable_equal_strpos.php.inc (100%) rename rules-tests/DowngradePhp80/Rector/FuncCall/{DowngradeMbStrContainsRector => DowngradeStrContainsWithMultibyteNeedleRector}/Fixture/offset_variable_strpos.php.inc (100%) rename rules-tests/DowngradePhp80/Rector/FuncCall/{DowngradeMbStrContainsRector => DowngradeStrContainsWithMultibyteNeedleRector}/Fixture/offset_variable_zero_equal_strpos.php.inc (100%) rename rules-tests/DowngradePhp80/Rector/FuncCall/{DowngradeMbStrContainsRector => DowngradeStrContainsWithMultibyteNeedleRector}/Fixture/offset_variable_zero_strpos.php.inc (100%) rename rules-tests/DowngradePhp80/Rector/FuncCall/{DowngradeMbStrContainsRector => DowngradeStrContainsWithMultibyteNeedleRector}/Fixture/skip_fixture_equal.php.inc (100%) rename rules-tests/DowngradePhp80/Rector/FuncCall/{DowngradeMbStrContainsRector => DowngradeStrContainsWithMultibyteNeedleRector}/Fixture/skip_str_contains.php.inc (100%) rename rules-tests/DowngradePhp80/Rector/FuncCall/{DowngradeMbStrContainsRector => DowngradeStrContainsWithMultibyteNeedleRector}/Fixture/skip_str_contains.php_with_mixed.php.inc (100%) rename rules-tests/DowngradePhp80/Rector/FuncCall/{DowngradeMbStrContainsRector => DowngradeStrContainsWithMultibyteNeedleRector}/Fixture/strstr.php.inc (100%) rename rules-tests/DowngradePhp80/Rector/FuncCall/{DowngradeMbStrContainsRector => DowngradeStrContainsWithMultibyteNeedleRector}/Fixture/the_other_way.php.inc (100%) rename rules-tests/DowngradePhp80/Rector/FuncCall/{DowngradeMbStrContainsRector => DowngradeStrContainsWithMultibyteNeedleRector}/Fixture/the_other_way_equal.php.inc (100%) rename rules-tests/DowngradePhp80/Rector/FuncCall/{DowngradeMbStrContainsRector => DowngradeStrContainsWithMultibyteNeedleRector}/config/configured_rule.php (100%) diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/DowngradeMbStrContainsRectorTest.php b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/DowngradeStrContainsWithMultibyteNeedleRectorTest.php similarity index 100% rename from rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/DowngradeMbStrContainsRectorTest.php rename to rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/DowngradeStrContainsWithMultibyteNeedleRectorTest.php diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/fixture_equal.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/fixture_equal.php.inc similarity index 100% rename from rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/fixture_equal.php.inc rename to rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/fixture_equal.php.inc diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/identical_mb_strpos.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/identical_mb_strpos.php.inc similarity index 100% rename from rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/identical_mb_strpos.php.inc rename to rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/identical_mb_strpos.php.inc diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/not_equal_mb_strstr.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/not_equal_mb_strstr.php.inc similarity index 100% rename from rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/not_equal_mb_strstr.php.inc rename to rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/not_equal_mb_strstr.php.inc diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/not_str_contains.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/not_str_contains.php.inc similarity index 100% rename from rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/not_str_contains.php.inc rename to rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/not_str_contains.php.inc diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/not_strstr.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/not_strstr.php.inc similarity index 100% rename from rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/not_strstr.php.inc rename to rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/not_strstr.php.inc diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_equal_strpos.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/offset_equal_strpos.php.inc similarity index 100% rename from rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_equal_strpos.php.inc rename to rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/offset_equal_strpos.php.inc diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_expression_equal_strpos.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/offset_expression_equal_strpos.php.inc similarity index 100% rename from rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_expression_equal_strpos.php.inc rename to rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/offset_expression_equal_strpos.php.inc diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_expression_mb_strpos.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/offset_expression_mb_strpos.php.inc similarity index 100% rename from rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_expression_mb_strpos.php.inc rename to rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/offset_expression_mb_strpos.php.inc diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_negative_equal_strpos.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/offset_negative_equal_strpos.php.inc similarity index 100% rename from rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_negative_equal_strpos.php.inc rename to rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/offset_negative_equal_strpos.php.inc diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_negative_strpos.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/offset_negative_strpos.php.inc similarity index 100% rename from rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_negative_strpos.php.inc rename to rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/offset_negative_strpos.php.inc diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_strpos.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/offset_strpos.php.inc similarity index 100% rename from rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_strpos.php.inc rename to rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/offset_strpos.php.inc diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_equal_strpos.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/offset_variable_equal_strpos.php.inc similarity index 100% rename from rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_equal_strpos.php.inc rename to rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/offset_variable_equal_strpos.php.inc diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_strpos.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/offset_variable_strpos.php.inc similarity index 100% rename from rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_strpos.php.inc rename to rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/offset_variable_strpos.php.inc diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_zero_equal_strpos.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/offset_variable_zero_equal_strpos.php.inc similarity index 100% rename from rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_zero_equal_strpos.php.inc rename to rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/offset_variable_zero_equal_strpos.php.inc diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_zero_strpos.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/offset_variable_zero_strpos.php.inc similarity index 100% rename from rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/offset_variable_zero_strpos.php.inc rename to rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/offset_variable_zero_strpos.php.inc diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/skip_fixture_equal.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/skip_fixture_equal.php.inc similarity index 100% rename from rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/skip_fixture_equal.php.inc rename to rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/skip_fixture_equal.php.inc diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/skip_str_contains.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/skip_str_contains.php.inc similarity index 100% rename from rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/skip_str_contains.php.inc rename to rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/skip_str_contains.php.inc diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/skip_str_contains.php_with_mixed.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/skip_str_contains.php_with_mixed.php.inc similarity index 100% rename from rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/skip_str_contains.php_with_mixed.php.inc rename to rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/skip_str_contains.php_with_mixed.php.inc diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/strstr.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/strstr.php.inc similarity index 100% rename from rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/strstr.php.inc rename to rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/strstr.php.inc diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/the_other_way.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/the_other_way.php.inc similarity index 100% rename from rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/the_other_way.php.inc rename to rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/the_other_way.php.inc diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/the_other_way_equal.php.inc b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/the_other_way_equal.php.inc similarity index 100% rename from rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/Fixture/the_other_way_equal.php.inc rename to rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/Fixture/the_other_way_equal.php.inc diff --git a/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/config/configured_rule.php b/rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/config/configured_rule.php similarity index 100% rename from rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector/config/configured_rule.php rename to rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector/config/configured_rule.php From cdb3f07afca58da2e6a224e6bb720c51808994ff Mon Sep 17 00:00:00 2001 From: Arshid Date: Thu, 18 Sep 2025 07:19:58 +0530 Subject: [PATCH 12/13] DowngradeMbStrContainsRector --- ...ctor.php => DowngradeStrContainsWithMultibyteNeedleRector.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename rules/DowngradePhp80/Rector/FuncCall/{DowngradeMbStrContainsRector.php => DowngradeStrContainsWithMultibyteNeedleRector.php} (100%) diff --git a/rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php b/rules/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector.php similarity index 100% rename from rules/DowngradePhp80/Rector/FuncCall/DowngradeMbStrContainsRector.php rename to rules/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector.php From 046c1b107f4fa4d4129e7bdf8ffb238e23563c2c Mon Sep 17 00:00:00 2001 From: Arshid Date: Thu, 18 Sep 2025 07:22:29 +0530 Subject: [PATCH 13/13] DowngradeMbStrContainsRector --- .../DowngradeStrContainsWithMultibyteNeedleRector.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rules/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector.php b/rules/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector.php index b2916de2..00d16022 100644 --- a/rules/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector.php +++ b/rules/DowngradePhp80/Rector/FuncCall/DowngradeStrContainsWithMultibyteNeedleRector.php @@ -86,7 +86,7 @@ public function refactor(Node $node): Identical | NotIdentical | null $offset = null; if ($haystack instanceof FuncCall) { - + if (! $this->isName($haystack->name, 'mb_substr')) { return null; } @@ -99,9 +99,11 @@ public function refactor(Node $node): Identical | NotIdentical | null if (isset($substrArg[0]) && ! $substrArg[0] instanceof Arg) { return null; } + if (isset($substrArg[1]) && ! $substrArg[1] instanceof Arg) { return null; } + $haystack = $substrArg[0]; $offset = $substrArg[1]; }