Skip to content

Commit 91c43e6

Browse files
committed
[CodeQuality] Deprecate SimplifyStrposLowerRector as niche rule, not part of PHP upgrade path
1 parent 3ba1a81 commit 91c43e6

7 files changed

Lines changed: 8 additions & 153 deletions

File tree

‎rules-tests/CodeQuality/Rector/FuncCall/SimplifyStrposLowerRector/Fixture/skip_dynamic_second_arg.php.inc‎

Lines changed: 0 additions & 14 deletions
This file was deleted.

‎rules-tests/CodeQuality/Rector/FuncCall/SimplifyStrposLowerRector/Fixture/skip_has_uppercase_second_arg.php.inc‎

Lines changed: 0 additions & 14 deletions
This file was deleted.

‎rules-tests/CodeQuality/Rector/FuncCall/SimplifyStrposLowerRector/Fixture/strpos.php.inc‎

Lines changed: 0 additions & 39 deletions
This file was deleted.

‎rules-tests/CodeQuality/Rector/FuncCall/SimplifyStrposLowerRector/SimplifyStrposLowerRectorTest.php‎

Lines changed: 0 additions & 28 deletions
This file was deleted.

‎rules-tests/CodeQuality/Rector/FuncCall/SimplifyStrposLowerRector/config/configured_rule.php‎

Lines changed: 0 additions & 9 deletions
This file was deleted.

‎rules/CodeQuality/Rector/FuncCall/SimplifyStrposLowerRector.php‎

Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,19 @@
44

55
namespace Rector\CodeQuality\Rector\FuncCall;
66

7-
use Nette\Utils\Strings;
87
use PhpParser\Node;
98
use PhpParser\Node\Expr\FuncCall;
10-
use PhpParser\Node\Name;
11-
use PhpParser\Node\Scalar\String_;
9+
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
10+
use Rector\Exception\ShouldNotHappenException;
1211
use Rector\Rector\AbstractRector;
1312
use Rector\RuleDoc\CodeSample\CodeSample;
1413
use Rector\RuleDoc\RuleDefinition;
1514

1615
/**
17-
* @see \Rector\Tests\CodeQuality\Rector\FuncCall\SimplifyStrposLowerRector\SimplifyStrposLowerRectorTest
16+
* @deprecated This rule is deprecated, as it handles a niche strpos(strtolower()) case that is not part of the PHP upgrade path.
1817
*/
19-
final class SimplifyStrposLowerRector extends AbstractRector
18+
final class SimplifyStrposLowerRector extends AbstractRector implements DeprecatedInterface
2019
{
21-
/**
22-
* @see https://regex101.com/r/Jokjt8/1
23-
*/
24-
private const string UPPERCASE_REGEX = '#[A-Z]#';
25-
2620
public function getRuleDefinition(): RuleDefinition
2721
{
2822
return new RuleDefinition(
@@ -44,42 +38,9 @@ public function getNodeTypes(): array
4438
*/
4539
public function refactor(Node $node): ?Node
4640
{
47-
if (! $this->isName($node, 'strpos')) {
48-
return null;
49-
}
50-
51-
if ($node->isFirstClassCallable()) {
52-
return null;
53-
}
54-
55-
$args = $node->getArgs();
56-
if (! isset($args[0], $args[1])) {
57-
return null;
58-
}
59-
60-
$firstArg = $args[0];
61-
if (! $firstArg->value instanceof FuncCall) {
62-
return null;
63-
}
64-
65-
$innerFuncCall = $firstArg->value;
66-
if (! $this->isName($innerFuncCall, 'strtolower')) {
67-
return null;
68-
}
69-
70-
$secondArg = $args[1];
71-
if (! $secondArg->value instanceof String_) {
72-
return null;
73-
}
74-
75-
if (Strings::match($secondArg->value->value, self::UPPERCASE_REGEX) !== null) {
76-
return null;
77-
}
78-
79-
// pop 1 level up
80-
$node->args[0] = $innerFuncCall->getArgs()[0];
81-
$node->name = new Name('stripos');
82-
83-
return $node;
41+
throw new ShouldNotHappenException(sprintf(
42+
'"%s" rule is deprecated, as it handles a niche strpos(strtolower()) case that is not part of the PHP upgrade path',
43+
self::class
44+
));
8445
}
8546
}

‎src/Config/Level/CodeQualityLevel.php‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
use Rector\CodeQuality\Rector\FuncCall\SetTypeToCastRector;
4444
use Rector\CodeQuality\Rector\FuncCall\SimplifyFuncGetArgsCountRector;
4545
use Rector\CodeQuality\Rector\FuncCall\SimplifyInArrayValuesRector;
46-
use Rector\CodeQuality\Rector\FuncCall\SimplifyStrposLowerRector;
4746
use Rector\CodeQuality\Rector\FuncCall\SingleInArrayToCompareRector;
4847
use Rector\CodeQuality\Rector\FuncCall\SortCallLikeNamedArgsRector;
4948
use Rector\CodeQuality\Rector\Identical\BooleanNotIdenticalToNotIdenticalRector;
@@ -120,7 +119,6 @@ final class CodeQualityLevel
120119
SimplifyForeachToCoalescingRector::class,
121120
SimplifyFuncGetArgsCountRector::class,
122121
SimplifyInArrayValuesRector::class,
123-
SimplifyStrposLowerRector::class,
124122
SimplifyArraySearchRector::class,
125123
SimplifyConditionsRector::class,
126124
SimplifyIfNotNullReturnRector::class,

0 commit comments

Comments
 (0)