44
55namespace Rector \CodeQuality \Rector \FuncCall ;
66
7- use Nette \Utils \Strings ;
87use PhpParser \Node ;
98use 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 ;
1211use Rector \Rector \AbstractRector ;
1312use Rector \RuleDoc \CodeSample \CodeSample ;
1413use 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}
0 commit comments