diff --git a/rules-tests/CodeQuality/Rector/FuncCall/SimplifyStrposLowerRector/Fixture/skip_dynamic_second_arg.php.inc b/rules-tests/CodeQuality/Rector/FuncCall/SimplifyStrposLowerRector/Fixture/skip_dynamic_second_arg.php.inc deleted file mode 100644 index 915922b780c..00000000000 --- a/rules-tests/CodeQuality/Rector/FuncCall/SimplifyStrposLowerRector/Fixture/skip_dynamic_second_arg.php.inc +++ /dev/null @@ -1,14 +0,0 @@ - ------ - diff --git a/rules-tests/CodeQuality/Rector/FuncCall/SimplifyStrposLowerRector/SimplifyStrposLowerRectorTest.php b/rules-tests/CodeQuality/Rector/FuncCall/SimplifyStrposLowerRector/SimplifyStrposLowerRectorTest.php deleted file mode 100644 index 2068a172eba..00000000000 --- a/rules-tests/CodeQuality/Rector/FuncCall/SimplifyStrposLowerRector/SimplifyStrposLowerRectorTest.php +++ /dev/null @@ -1,28 +0,0 @@ -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/CodeQuality/Rector/FuncCall/SimplifyStrposLowerRector/config/configured_rule.php b/rules-tests/CodeQuality/Rector/FuncCall/SimplifyStrposLowerRector/config/configured_rule.php deleted file mode 100644 index 0f860e40ce9..00000000000 --- a/rules-tests/CodeQuality/Rector/FuncCall/SimplifyStrposLowerRector/config/configured_rule.php +++ /dev/null @@ -1,9 +0,0 @@ -withRules([SimplifyStrposLowerRector::class]); diff --git a/rules/CodeQuality/Rector/FuncCall/SimplifyStrposLowerRector.php b/rules/CodeQuality/Rector/FuncCall/SimplifyStrposLowerRector.php index 12bf2889ea3..d703a049feb 100644 --- a/rules/CodeQuality/Rector/FuncCall/SimplifyStrposLowerRector.php +++ b/rules/CodeQuality/Rector/FuncCall/SimplifyStrposLowerRector.php @@ -4,25 +4,19 @@ namespace Rector\CodeQuality\Rector\FuncCall; -use Nette\Utils\Strings; use PhpParser\Node; use PhpParser\Node\Expr\FuncCall; -use PhpParser\Node\Name; -use PhpParser\Node\Scalar\String_; +use Rector\Configuration\Deprecation\Contract\DeprecatedInterface; +use Rector\Exception\ShouldNotHappenException; use Rector\Rector\AbstractRector; use Rector\RuleDoc\CodeSample\CodeSample; use Rector\RuleDoc\RuleDefinition; /** - * @see \Rector\Tests\CodeQuality\Rector\FuncCall\SimplifyStrposLowerRector\SimplifyStrposLowerRectorTest + * @deprecated This rule is deprecated, as it handles a niche strpos(strtolower()) case that is not part of the PHP upgrade path. */ -final class SimplifyStrposLowerRector extends AbstractRector +final class SimplifyStrposLowerRector extends AbstractRector implements DeprecatedInterface { - /** - * @see https://regex101.com/r/Jokjt8/1 - */ - private const string UPPERCASE_REGEX = '#[A-Z]#'; - public function getRuleDefinition(): RuleDefinition { return new RuleDefinition( @@ -44,42 +38,9 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { - if (! $this->isName($node, 'strpos')) { - return null; - } - - if ($node->isFirstClassCallable()) { - return null; - } - - $args = $node->getArgs(); - if (! isset($args[0], $args[1])) { - return null; - } - - $firstArg = $args[0]; - if (! $firstArg->value instanceof FuncCall) { - return null; - } - - $innerFuncCall = $firstArg->value; - if (! $this->isName($innerFuncCall, 'strtolower')) { - return null; - } - - $secondArg = $args[1]; - if (! $secondArg->value instanceof String_) { - return null; - } - - if (Strings::match($secondArg->value->value, self::UPPERCASE_REGEX) !== null) { - return null; - } - - // pop 1 level up - $node->args[0] = $innerFuncCall->getArgs()[0]; - $node->name = new Name('stripos'); - - return $node; + throw new ShouldNotHappenException(sprintf( + '"%s" rule is deprecated, as it handles a niche strpos(strtolower()) case that is not part of the PHP upgrade path', + self::class + )); } } diff --git a/src/Config/Level/CodeQualityLevel.php b/src/Config/Level/CodeQualityLevel.php index 79f3e963fe0..17026f84675 100644 --- a/src/Config/Level/CodeQualityLevel.php +++ b/src/Config/Level/CodeQualityLevel.php @@ -42,7 +42,6 @@ use Rector\CodeQuality\Rector\FuncCall\RemoveSoleValueSprintfRector; use Rector\CodeQuality\Rector\FuncCall\SimplifyFuncGetArgsCountRector; use Rector\CodeQuality\Rector\FuncCall\SimplifyInArrayValuesRector; -use Rector\CodeQuality\Rector\FuncCall\SimplifyStrposLowerRector; use Rector\CodeQuality\Rector\FuncCall\SingleInArrayToCompareRector; use Rector\CodeQuality\Rector\FuncCall\SortCallLikeNamedArgsRector; use Rector\CodeQuality\Rector\Identical\BooleanNotIdenticalToNotIdenticalRector; @@ -119,7 +118,6 @@ final class CodeQualityLevel SimplifyForeachToCoalescingRector::class, SimplifyFuncGetArgsCountRector::class, SimplifyInArrayValuesRector::class, - SimplifyStrposLowerRector::class, SimplifyArraySearchRector::class, SimplifyConditionsRector::class, SimplifyIfNotNullReturnRector::class,