Skip to content

Commit 5814187

Browse files
authored
[StrContainsRector] also replace multibyte functions fro strpos and strstr (#6901)
1 parent 8dfc7aa commit 5814187

4 files changed

Lines changed: 57 additions & 7 deletions

File tree

config/set/php85.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,5 @@
66
use Rector\Php85\Rector\ArrayDimFetch\ArrayFirstLastRector;
77

88
return static function (RectorConfig $rectorConfig): void {
9-
$rectorConfig->rules(
10-
[
11-
ArrayFirstLastRector::class,
12-
]
13-
);
9+
$rectorConfig->rules([ArrayFirstLastRector::class]);
1410
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php80\Rector\NotIdentical\StrContainsRector\Fixture;
4+
5+
class MultibyteStrposFunction
6+
{
7+
public function run()
8+
{
9+
$isMatch = mb_strpos('abc', 'a') !== false;
10+
}
11+
}
12+
13+
?>
14+
-----
15+
<?php
16+
17+
namespace Rector\Tests\Php80\Rector\NotIdentical\StrContainsRector\Fixture;
18+
19+
class MultibyteStrposFunction
20+
{
21+
public function run()
22+
{
23+
$isMatch = str_contains('abc', 'a');
24+
}
25+
}
26+
27+
?>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php80\Rector\NotIdentical\StrContainsRector\Fixture;
4+
5+
class MultibyteStrstrFunction
6+
{
7+
public function run()
8+
{
9+
$isMatch = mb_strstr('abc', 'a') === false;
10+
}
11+
}
12+
13+
?>
14+
-----
15+
<?php
16+
17+
namespace Rector\Tests\Php80\Rector\NotIdentical\StrContainsRector\Fixture;
18+
19+
class MultibyteStrstrFunction
20+
{
21+
public function run()
22+
{
23+
$isMatch = !str_contains('abc', 'a');
24+
}
25+
}
26+
27+
?>

rules/Php80/Rector/NotIdentical/StrContainsRector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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'

0 commit comments

Comments
 (0)