Skip to content

[StrContainsRector] also replace multibyte functions fro strpos and strstr #6901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions config/set/php85.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,5 @@
use Rector\Php85\Rector\ArrayDimFetch\ArrayFirstLastRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rules(
[
ArrayFirstLastRector::class,
]
);
$rectorConfig->rules([ArrayFirstLastRector::class]);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Rector\Tests\Php80\Rector\NotIdentical\StrContainsRector\Fixture;

class MultibyteStrposFunction
{
public function run()
{
$isMatch = mb_strpos('abc', 'a') !== false;
}
}

?>
-----
<?php

namespace Rector\Tests\Php80\Rector\NotIdentical\StrContainsRector\Fixture;

class MultibyteStrposFunction
{
public function run()
{
$isMatch = str_contains('abc', 'a');
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Rector\Tests\Php80\Rector\NotIdentical\StrContainsRector\Fixture;

class MultibyteStrstrFunction
{
public function run()
{
$isMatch = mb_strstr('abc', 'a') === false;
}
}

?>
-----
<?php

namespace Rector\Tests\Php80\Rector\NotIdentical\StrContainsRector\Fixture;

class MultibyteStrstrFunction
{
public function run()
{
$isMatch = !str_contains('abc', 'a');
}
}

?>
4 changes: 2 additions & 2 deletions rules/Php80/Rector/NotIdentical/StrContainsRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class StrContainsRector extends AbstractRector implements MinPhpVersionInt
/**
* @var string[]
*/
private const OLD_STR_NAMES = ['strpos', 'strstr'];
private const OLD_STR_NAMES = ['mb_strpos', 'mb_strstr', 'strpos', 'strstr'];

public function __construct(
private readonly ValueResolver $valueResolver
Expand All @@ -47,7 +47,7 @@ public function provideMinPhpVersion(): int
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
'Replace strpos() !== false and strstr() with str_contains()',
'Replace strpos|mb_strpos() !== false and strstr()|mb_strstr() with str_contains()',
[
new CodeSample(
<<<'CODE_SAMPLE'
Expand Down