Skip to content

Commit

Permalink
PHP80 string helpers loose comparison (#3246)
Browse files Browse the repository at this point in the history
  • Loading branch information
N-Silbernagel committed Dec 29, 2022
1 parent 0146fc0 commit 6bd6b3c
Show file tree
Hide file tree
Showing 42 changed files with 817 additions and 63 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture;

class Fixture
{
public function run()
{
$isMatch = substr($haystack, -strlen($needle)) == $needle;

$isMatch = $needle == substr($haystack, -strlen($needle));
}
}

?>
-----
<?php

namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture;

class Fixture
{
public function run()
{
$isMatch = str_ends_with($haystack, $needle);

$isMatch = str_ends_with($haystack, $needle);
}
}

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

namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture;

class HardCoded
{
public function run()
{
$isMatch = substr($haystack, -3) == 'foo';

$isMatch = 'foo' == substr($haystack, -3);
}
}

?>
-----
<?php

namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture;

class HardCoded
{
public function run()
{
$isMatch = str_ends_with($haystack, 'foo');

$isMatch = str_ends_with($haystack, 'foo');
}
}

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

namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture;

class HardCodedNotIdentical
{
public function run()
{
$isMatch = substr($haystack, -3) != 'foo';

$isMatch = 'foo' != substr($haystack, -3);
}
}

?>
-----
<?php

namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture;

class HardCodedNotIdentical
{
public function run()
{
$isMatch = !str_ends_with($haystack, 'foo');

$isMatch = !str_ends_with($haystack, 'foo');
}
}

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

namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture;

class SkipSubstrCompareNotZero
{
public function run()
{
$isMatch = substr_compare($haystack, $needle, -strlen($needle)) == 3;

$isMatch = 3 == substr_compare($haystack, $needle, -strlen($needle));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture;

class SubstrCompare
{
public function run()
{
$isMatch = substr_compare($haystack, $needle, -strlen($needle)) == 0;

$isMatch = 0 == substr_compare($haystack, $needle, -strlen($needle));
}
}

?>
-----
<?php

namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture;

class SubstrCompare
{
public function run()
{
$isMatch = str_ends_with($haystack, $needle);

$isMatch = str_ends_with($haystack, $needle);
}
}

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

namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture;

class SubstrCompare
{
public function run()
{
$isMatch = substr_compare($haystack, 'needle', -6) == 0;

$isMatch = 0 == substr_compare($haystack, 'needle', -6);
}
}

?>
-----
<?php

namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture;

class SubstrCompare
{
public function run()
{
$isMatch = str_ends_with($haystack, 'needle');

$isMatch = str_ends_with($haystack, 'needle');
}
}

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

namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture;

class SubstrCompareNot
{
public function run()
{
$isNotMatch = substr_compare($haystack, $needle, -strlen($needle)) != 0;

$isNotMatch = 0 != substr_compare($haystack, $needle, -strlen($needle));
}
}

?>
-----
<?php

namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture;

class SubstrCompareNot
{
public function run()
{
$isNotMatch = !str_ends_with($haystack, $needle);

$isNotMatch = !str_ends_with($haystack, $needle);
}
}

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

namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture;

class SubstrCompareNot
{
public function run()
{
$isNotMatch = substr_compare($haystack, 'needle', -6) != 0;

$isNotMatch = 0 != substr_compare($haystack, 'needle', -6);
}
}

?>
-----
<?php

namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture;

class SubstrCompareNot
{
public function run()
{
$isNotMatch = !str_ends_with($haystack, 'needle');

$isNotMatch = !str_ends_with($haystack, 'needle');
}
}

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

namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture;

class SubstrNotPrefix
{
public function run()
{
$isNotMatch = substr($haystack, -strlen($needle)) != $needle;

$isNotMatch = $needle != substr($haystack, -strlen($needle));
}
}

?>
-----
<?php

namespace Rector\Tests\Php80\Rector\Identical\StrEndsWithRector\Fixture;

class SubstrNotPrefix
{
public function run()
{
$isNotMatch = !str_ends_with($haystack, $needle);

$isNotMatch = !str_ends_with($haystack, $needle);
}
}

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

namespace Rector\Tests\Php80\Rector\Identical\StrStartsWithRector\Fixture;

class Fixture
{
public function run()
{
$isMatch = substr($haystack, 0, strlen($needle)) == $needle;
}
}

?>
-----
<?php

namespace Rector\Tests\Php80\Rector\Identical\StrStartsWithRector\Fixture;

class Fixture
{
public function run()
{
$isMatch = str_starts_with($haystack, $needle);
}
}

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

namespace Rector\Tests\Php80\Rector\Identical\StrStartsWithRector\Fixture;

class HardCoded
{
public function run()
{
$isMatch = substr($haystack, 0, 3) == 'foo';

$isMatch = 'foo' == substr($haystack, 0, 3);
}
}

?>
-----
<?php

namespace Rector\Tests\Php80\Rector\Identical\StrStartsWithRector\Fixture;

class HardCoded
{
public function run()
{
$isMatch = str_starts_with($haystack, 'foo');

$isMatch = str_starts_with($haystack, 'foo');
}
}

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

namespace Rector\Tests\Php80\Rector\Identical\StrStartsWithRector\Fixture;

class HardCodedNotIdentical
{
public function run()
{
$isMatch = substr($haystack, 0, 3) != 'foo';

$isMatch = 'foo' != substr($haystack, 0, 3);
}
}

?>
-----
<?php

namespace Rector\Tests\Php80\Rector\Identical\StrStartsWithRector\Fixture;

class HardCodedNotIdentical
{
public function run()
{
$isMatch = !str_starts_with($haystack, 'foo');

$isMatch = !str_starts_with($haystack, 'foo');
}
}

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

namespace Rector\Tests\Php80\Rector\Identical\StrStartsWithRector\Fixture;

class NotIdenticalSubstr
{
public function run()
{
$isNotMatch = substr($haystack, 0, strlen($needle)) != $needle;
}
}

?>
-----
<?php

namespace Rector\Tests\Php80\Rector\Identical\StrStartsWithRector\Fixture;

class NotIdenticalSubstr
{
public function run()
{
$isNotMatch = !str_starts_with($haystack, $needle);
}
}

?>

0 comments on commit 6bd6b3c

Please sign in to comment.