Find the best Rector rule to solve your problem


ClosureToArrowFunctionRector

Change closure to arrow function

 class SomeClass
 {
     public function run($meetups)
     {
-        return array_filter($meetups, function (Meetup $meetup) {
-            return is_object($meetup);
-        });
+        return array_filter($meetups, fn(Meetup $meetup) => is_object($meetup));
     }
 }
SETS:  PHP 7.4

FilterVarToAddSlashesRector

Change filter_var() with slash escaping to addslashes()

 $var= "Satya's here!";
-filter_var($var, FILTER_SANITIZE_MAGIC_QUOTES);
+addslashes($var);
SETS:  PHP 7.4

MoneyFormatToNumberFormatRector

Change money_format() to equivalent number_format()

-$value = money_format('%i', $value);
+$value = number_format(round($value, 2, PHP_ROUND_HALF_ODD), 2, '.', '');
SETS:  PHP 7.4

MbStrrposEncodingArgumentPositionRector

Change mb_strrpos() encoding argument position

-mb_strrpos($text, "abc", "UTF-8");
+mb_strrpos($text, "abc", 0, "UTF-8");
SETS:  PHP 7.4

HebrevcToNl2brHebrevRector

Change hebrevc($str) to nl2br(hebrev($str))

-hebrevc($str);
+nl2br(hebrev($str));
SETS:  PHP 7.4

ArrayKeyExistsOnPropertyRector

Change array_key_exists() on property to property_exists()

 class SomeClass
 {
      public $value;
 }
 $someClass = new SomeClass;

-array_key_exists('value', $someClass);
+property_exists($someClass, 'value');
SETS:  PHP 7.4

RestoreIncludePathToIniRestoreRector

Change restore_include_path() to ini_restore("include_path")

-restore_include_path();
+ini_restore('include_path');
SETS:  PHP 7.4

RealToFloatTypeCastRector

Change deprecated (real) to (float)

 class SomeClass
 {
     public function run()
     {
-        $number = (real) 5;
+        $number = (float) 5;
         $number = (float) 5;
         $number = (double) 5;
     }
 }
SETS:  PHP 7.4

ExportToReflectionFunctionRector

Change export() to ReflectionFunction alternatives

-$reflectionFunction = ReflectionFunction::export('foo');
-$reflectionFunctionAsString = ReflectionFunction::export('foo', true);
+$reflectionFunction = new ReflectionFunction('foo');
+$reflectionFunctionAsString = (string) new ReflectionFunction('foo');
SETS:  PHP 7.4

RestoreDefaultNullToNullableTypePropertyRector

Add null default to properties with PHP 7.4 property nullable type

 class SomeClass
 {
-    public ?string $name;
+    public ?string $name = null;
 }
SETS:  PHP 7.4

NullCoalescingOperatorRector

Use null coalescing operator ??=

 $array = [];
-$array['user_id'] = $array['user_id'] ?? 'value';
+$array['user_id'] ??= 'value';
SETS:  PHP 7.4

ParenthesizeNestedTernaryRector

Add parentheses to nested ternary

-$value = $a ? $b : $a ?: null;
+$value = ($a ? $b : $a) ?: null;
SETS:  PHP 7.4

CurlyToSquareBracketArrayStringRector

Change curly based array and string to square bracket

 $string = 'test';
-echo $string{0};
+echo $string[0];

 $array = ['test'];
-echo $array{0};
+echo $array[0];
SETS:  PHP 7.4

Configurable

RenameFunctionRector

Turns defined function call new one.

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