@@ -32,7 +32,7 @@ final class StrContainsRector extends AbstractRector implements MinPhpVersionInt
3232 /**
3333 * @var string[]
3434 */
35- private const OLD_STR_NAMES = ['strpos ' , 'strstr ' ];
35+ private const OLD_STR_NAMES = ['mb_strpos ' , ' mb_strstr ' , ' strpos ' , 'strstr ' ];
3636
3737 public function __construct (
3838 private readonly ValueResolver $ valueResolver
@@ -47,7 +47,7 @@ public function provideMinPhpVersion(): int
4747 public function getRuleDefinition (): RuleDefinition
4848 {
4949 return new RuleDefinition (
50- 'Replace strpos() !== false and strstr() with str_contains() ' ,
50+ 'Replace strpos|mb_strpos () !== false and strstr()|mb_strstr() with str_contains() ' ,
5151 [
5252 new CodeSample (
5353 <<<'CODE_SAMPLE'
@@ -97,12 +97,20 @@ public function refactor(Node $node): ?Node
9797 return null ;
9898 }
9999
100+ if ($ this ->isNames ($ funcCall ->name , ['mb_strpos ' , 'mb_strstr ' ]) && isset ($ funcCall ->getArgs ()[3 ])) {
101+ if (! $ this ->valueResolver ->isNull ($ funcCall ->getArgs ()[3 ]->value )) {
102+ return null ;
103+ }
104+
105+ unset($ funcCall ->args [3 ]);
106+ }
107+
100108 if (isset ($ funcCall ->getArgs ()[2 ])) {
101109 $ secondArg = $ funcCall ->getArgs ()[2 ];
102110
103- if ($ this ->isName ($ funcCall ->name , 'strpos ' ) && ! $ this ->isIntegerZero ($ secondArg ->value )) {
111+ if ($ this ->isNames ($ funcCall ->name , [ 'strpos ' , ' mb_strpos ' ] ) && ! $ this ->isIntegerZero ($ secondArg ->value )) {
104112 $ funcCall ->args [0 ] = new Arg ($ this ->nodeFactory ->createFuncCall (
105- ' substr ' ,
113+ $ this -> isName ( $ funcCall -> name , ' strpos ' ) ? ' substr ' : ' mb_substr ' ,
106114 [$ funcCall ->args [0 ], $ secondArg ]
107115 ));
108116 }
0 commit comments