File tree Expand file tree Collapse file tree
rules-tests/Php80/Rector/NotIdentical/StrContainsRector/Fixture
rules/Php80/Rector/NotIdentical Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Tests \Php80 \Rector \NotIdentical \StrContainsRector \Fixture ;
4+
5+ class SkipEmptyNeedleStrpos
6+ {
7+ public function run ()
8+ {
9+ return strpos ('abc ' , '' ) !== false ;
10+ }
11+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Tests \Php80 \Rector \NotIdentical \StrContainsRector \Fixture ;
4+
5+ class SkipEmptyNeedleStrstr
6+ {
7+ public function run ()
8+ {
9+ return strstr ('abc ' , '' ) !== false ;
10+ }
11+ }
Original file line number Diff line number Diff line change 1515use PhpParser \Node \Expr \FuncCall ;
1616use PhpParser \Node \Name ;
1717use PhpParser \Node \Scalar \Int_ ;
18+ use PhpParser \Node \Scalar \String_ ;
1819use Rector \Php80 \NodeResolver \StrFalseComparisonResolver ;
1920use Rector \Rector \AbstractRector ;
2021use Rector \ValueObject \PhpVersionFeature ;
@@ -97,6 +98,11 @@ public function refactor(Node $node): ?Node
9798 return null ;
9899 }
99100
101+ $ args = $ funcCall ->getArgs ();
102+ if (isset ($ args [1 ]) && $ this ->isEmptyStringNeedle ($ args [1 ]->value )) {
103+ return null ;
104+ }
105+
100106 if (isset ($ funcCall ->getArgs ()[2 ])) {
101107 $ secondArg = $ funcCall ->getArgs ()[2 ];
102108
@@ -132,4 +138,13 @@ private function isIntegerZero(Expr $expr): bool
132138
133139 return $ expr ->value === 0 ;
134140 }
141+
142+ private function isEmptyStringNeedle (Expr $ expr ): bool
143+ {
144+ if (! $ expr instanceof String_) {
145+ return false ;
146+ }
147+
148+ return $ expr ->value === '' ;
149+ }
135150}
You can’t perform that action at this time.
0 commit comments