1515use PhpParser \Node \Expr \FuncCall ;
1616use PhpParser \Node \Name ;
1717use PhpParser \Node \Scalar \Int_ ;
18+ use Rector \Php80 \NodeResolver \StrFalseComparisonResolver ;
1819use Rector \PhpParser \Node \Value \ValueResolver ;
1920use Rector \Rector \AbstractRector ;
2021use Rector \ValueObject \PhpVersionFeature ;
@@ -35,7 +36,7 @@ final class StrContainsRector extends AbstractRector implements MinPhpVersionInt
3536 private const OLD_STR_NAMES = ['strpos ' , 'strstr ' ];
3637
3738 public function __construct (
38- private readonly ValueResolver $ valueResolver
39+ private readonly StrFalseComparisonResolver $ strFalseComparisonResolver
3940 ) {
4041 }
4142
@@ -87,7 +88,7 @@ public function getNodeTypes(): array
8788 */
8889 public function refactor (Node $ node ): ?Node
8990 {
90- $ funcCall = $ this ->matchIdenticalOrNotIdenticalToFalse ($ node );
91+ $ funcCall = $ this ->strFalseComparisonResolver -> resolve ($ node, self :: OLD_STR_NAMES );
9192
9293 if (! $ funcCall instanceof FuncCall) {
9394 return null ;
@@ -124,39 +125,6 @@ public function providePolyfillPackage(): string
124125 return PolyfillPackage::PHP_80 ;
125126 }
126127
127- private function matchIdenticalOrNotIdenticalToFalse (Identical | NotIdentical | Equal | NotEqual $ expr ): ?FuncCall
128- {
129- if ($ this ->valueResolver ->isFalse ($ expr ->left )) {
130- if (! $ expr ->right instanceof FuncCall) {
131- return null ;
132- }
133-
134- if (! $ this ->isNames ($ expr ->right , self ::OLD_STR_NAMES )) {
135- return null ;
136- }
137-
138- /** @var FuncCall $funcCall */
139- $ funcCall = $ expr ->right ;
140- return $ funcCall ;
141- }
142-
143- if ($ this ->valueResolver ->isFalse ($ expr ->right )) {
144- if (! $ expr ->left instanceof FuncCall) {
145- return null ;
146- }
147-
148- if (! $ this ->isNames ($ expr ->left , self ::OLD_STR_NAMES )) {
149- return null ;
150- }
151-
152- /** @var FuncCall $funcCall */
153- $ funcCall = $ expr ->left ;
154- return $ funcCall ;
155- }
156-
157- return null ;
158- }
159-
160128 private function isIntegerZero (Expr $ expr ): bool
161129 {
162130 if (! $ expr instanceof Int_) {
0 commit comments