Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 0 deletions config/set/downgrade-php80.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Rector\DowngradePhp80\Rector\Expression\DowngradeMatchToSwitchRector;
use Rector\DowngradePhp80\Rector\Expression\DowngradeThrowExprRector;
use Rector\DowngradePhp80\Rector\FuncCall\DowngradeArrayFilterNullableCallbackRector;
use Rector\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector;
use Rector\DowngradePhp80\Rector\FuncCall\DowngradeNumberFormatNoFourthArgRector;
use Rector\DowngradePhp80\Rector\FuncCall\DowngradeStrContainsRector;
use Rector\DowngradePhp80\Rector\FuncCall\DowngradeStrEndsWithRector;
Expand Down Expand Up @@ -70,6 +71,7 @@
DowngradePropertyPromotionRector::class,
DowngradeNonCapturingCatchesRector::class,
DowngradeStrContainsRector::class,
DowngradeMbStrContainsRector::class,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unregister this, there is no "mb_str_contains", only str_contains, that means that utilize strpos can be on purpose.

let user manually use if needed, dealing with user that may don't have mbstring extension or use strpos on purpose :)

user that use mb_ functions know why they are using the mb_ functions :)

DowngradeMatchToSwitchRector::class,
DowngradeClassOnObjectToGetClassRector::class,
DowngradeArbitraryExpressionsSupportRector::class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector;

use Iterator;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;

final class DowngradeMbStrContainsRectorTest extends AbstractRectorTestCase
{
#[DataProvider('provideData')]
public function test(string $filePath): void
{
$this->doTestFile($filePath);
}

public static function provideData(): Iterator
{
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

public function provideConfigFilePath(): string
{
return __DIR__ . '/config/configured_rule.php';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture;

class Fixture
{
public function run()
{
$isMatch = str_contains('😊abc', 'a');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am thinking if the mb_strpos() only when needle is exact string and has multibyte, the original str_contains() to strpos() already converted on DowngradeStrContainsRector, so should be a logic to verify that the needle has multibye, eg:

strlen($needle) !== mb_strlen($needle)

this, however, I prefer to not be part of downgrade php 8.0 set, as dealing with multibyte can be "there on purpose", user that needs exact change str_contains -> mb_strpos needs to enable manually as use and know the risk.

}
}

?>
-----
<?php

namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture;

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

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

namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture;

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

?>
-----
<?php

namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture;

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

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

namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture;

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

?>
-----
<?php

namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture;

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

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

namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture;

final class NoStrContains
{
public function run()
{
return ! str_contains('abc', 'b');
}
}

?>
-----
<?php

namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture;

final class NoStrContains
{
public function run()
{
return mb_strpos('abc', 'b') === false;
}
}

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

namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture;

class IdenticalStrstr
{
public function run()
{
$isMatch = !str_contains('abc', 'a');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these fixtures are invalid, as no multibyte in needle, only downgrade to mb_strpos when needle has multibyte char

$isMatch = !str_contains('😊abc', 😊'a');

}
}

?>
-----
<?php

namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture;

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

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

namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture;

class OffsetStrpos
{
public function run()
{
$isMatch = str_contains(mb_substr('abc', 1), 'a');
}
}
?>
-----
<?php

namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture;

class OffsetStrpos
{
public function run()
{
$isMatch = mb_strpos('abc', 'a', 1) !== false;
}
}
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture;

class OffsetExpressionStrpos
{
public function run()
{
$offset = 1;
$isMatch = str_contains(mb_substr('abc', $offset + 1), 'a');
}
}
?>
-----
<?php

namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture;

class OffsetExpressionStrpos
{
public function run()
{
$offset = 1;
$isMatch = mb_strpos('abc', 'a', $offset + 1) !== false;
}
}
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture;

class OffsetExpressionStrpos
{
public function run()
{
$offset = 1;
$isMatch = str_contains(mb_substr('abc', $offset + 1), 'a');
}
}
?>
-----
<?php

namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture;

class OffsetExpressionStrpos
{
public function run()
{
$offset = 1;
$isMatch = mb_strpos('abc', 'a', $offset + 1) !== false;
}
}
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture;

class OffsetNegativeStrpos
{
public function run()
{
$isMatch = str_contains(mb_substr('abc', -1), 'a');
}
}
?>
-----
<?php

namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture;

class OffsetNegativeStrpos
{
public function run()
{
$isMatch = mb_strpos('abc', 'a', -1) !== false;
}
}
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture;

class OffsetNegativeStrpos
{
public function run()
{
$isMatch = str_contains(mb_substr('abc', -1), 'a');
}
}
?>
-----
<?php

namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture;

class OffsetNegativeStrpos
{
public function run()
{
$isMatch = mb_strpos('abc', 'a', -1) !== false;
}
}
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture;

class OffsetStrpos
{
public function run()
{
$isMatch = str_contains(mb_substr('abc', 1), 'a');
}
}
?>
-----
<?php

namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture;

class OffsetStrpos
{
public function run()
{
$isMatch = mb_strpos('abc', 'a', 1) !== false;
}
}
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture;

class OffsetVariableStrpos
{
public function run()
{
$offset = 1;
$isMatch = str_contains(mb_substr('abc', $offset), 'a');
}
}
?>
-----
<?php

namespace Rector\Tests\DowngradePhp80\Rector\FuncCall\DowngradeMbStrContainsRector\Fixture;

class OffsetVariableStrpos
{
public function run()
{
$offset = 1;
$isMatch = mb_strpos('abc', 'a', $offset) !== false;
}
}
?>
Loading