Find the best Rector rule to solve your problem


ArrayKeyFirstLastRector

Make use of array_key_first() and array_key_last()

-reset($items);
-$firstKey = key($items);
+$firstKey = array_key_first($items);
SETS:  PHP 7.3 Polyfills

IsCountableRector

Changes is_array + Countable check to is_countable

-is_array($foo) || $foo instanceof Countable;
+is_countable($foo);
SETS:  PHP 7.3 Polyfills

StrEndsWithRector

Change helper functions to str_ends_with()

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

-        $isNotMatch = substr($haystack, -strlen($needle)) !== $needle;
+        $isNotMatch = !str_ends_with($haystack, $needle);
     }
 }
SETS:  PHP 8.0 Polyfills

StrStartsWithRector

Change helper functions to str_starts_with()

 class SomeClass
 {
     public function run()
     {
-        $isMatch = substr($haystack, 0, strlen($needle)) === $needle;
+        $isMatch = str_starts_with($haystack, $needle);

-        $isNotMatch = substr($haystack, 0, strlen($needle)) !== $needle;
+        $isNotMatch = ! str_starts_with($haystack, $needle);
     }
 }
SETS:  PHP 8.0 Polyfills

StrContainsRector

Replace strpos() !== false and strstr() with str_contains()

 class SomeClass
 {
     public function run()
     {
-        return strpos('abc', 'a') !== false;
+        return str_contains('abc', 'a');
     }
 }
SETS:  PHP 8.0 Polyfills

GetDebugTypeRector

Change ternary type resolve to get_debug_type()

 class SomeClass
 {
     public function run($value)
     {
-        return is_object($value) ? get_class($value) : gettype($value);
+        return get_debug_type($value);
     }
 }
SETS:  PHP 8.0 Polyfills