Find the best Rector rule to solve your problem


WhileEachToForeachRector

each() function is deprecated, use foreach() instead.

-while (list($key, $callback) = each($callbacks)) {
+foreach ($callbacks as $key => $callback) {
     // ...
 }
SETS:  PHP 7.2

StringsAssertNakedRector

String asserts must be passed directly to assert()

 function nakedAssert()
 {
-    assert('true === true');
-    assert("true === true");
+    assert(true === true);
+    assert(true === true);
 }
SETS:  PHP 7.2

StringifyDefineRector

Make first argument of define() string

 class SomeClass
 {
     public function run(int $a)
     {
-         define(CONSTANT_2, 'value');
+         define('CONSTANT_2', 'value');
          define('CONSTANT', 'value');
     }
 }
SETS:  PHP 7.2

ParseStrWithResultArgumentRector

Use $result argument in parse_str() function

-parse_str($this->query);
-$data = get_defined_vars();
+parse_str($this->query, $result);
+$data = $result;
SETS:  PHP 7.2

CreateFunctionToAnonymousFunctionRector

Use anonymous functions instead of deprecated create_function()

 class ClassWithCreateFunction
 {
     public function run()
     {
-        $callable = create_function('$matches', "return '$delimiter' . strtolower(\$matches[1]);");
+        $callable = function($matches) use ($delimiter) {
+            return $delimiter . strtolower($matches[1]);
+        };
     }
 }
SETS:  PHP 7.2

GetClassOnNullRector

Null is no more allowed in get_class()

 final class SomeClass
 {
     public function getItem()
     {
         $value = null;
-        return get_class($value);
+        return $value !== null ? get_class($value) : self::class;
     }
 }
SETS:  PHP 7.2

ReplaceEachAssignmentWithKeyCurrentRector

Replace each() assign outside loop

 $array = ['b' => 1, 'a' => 2];

-$eachedArray = each($array);
+$eachedArray[1] = current($array);
+$eachedArray['value'] = current($array);
+$eachedArray[0] = key($array);
+$eachedArray['key'] = key($array);
+
+next($array);
SETS:  PHP 7.2

ListEachRector

each() function is deprecated, use key() and current() instead

-list($key, $callback) = each($callbacks);
+$key = key($callbacks);
+$callback = current($callbacks);
+next($callbacks);
SETS:  PHP 7.2

UnsetCastRector

Removes (unset) cast

-$different = (unset) $value;
+$different = null;

-$value = (unset) $value;
+unset($value);
SETS:  PHP 7.2

Configurable

RenameFunctionRector

Turns defined function call new one.

-view("...", []);
+Laravel\Templating\render("...", []);