Find the best Rector rule to solve your problem
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));
}
}
Change filter_var() with slash escaping to addslashes()
$var= "Satya's here!";
-filter_var($var, FILTER_SANITIZE_MAGIC_QUOTES);
+addslashes($var);
Change money_format() to equivalent number_format()
-$value = money_format('%i', $value);
+$value = number_format(round($value, 2, PHP_ROUND_HALF_ODD), 2, '.', '');
Change mb_strrpos() encoding argument position
-mb_strrpos($text, "abc", "UTF-8");
+mb_strrpos($text, "abc", 0, "UTF-8");
Change hebrevc($str) to nl2br(hebrev($str))
-hebrevc($str);
+nl2br(hebrev($str));
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');
Change restore_include_path() to ini_restore("include_path")
-restore_include_path();
+ini_restore('include_path');
Change deprecated (real) to (float)
class SomeClass
{
public function run()
{
- $number = (real) 5;
+ $number = (float) 5;
$number = (float) 5;
$number = (double) 5;
}
}
Change export() to ReflectionFunction alternatives
-$reflectionFunction = ReflectionFunction::export('foo');
-$reflectionFunctionAsString = ReflectionFunction::export('foo', true);
+$reflectionFunction = new ReflectionFunction('foo');
+$reflectionFunctionAsString = (string) new ReflectionFunction('foo');
Add null default to properties with PHP 7.4 property nullable type
class SomeClass
{
- public ?string $name;
+ public ?string $name = null;
}
Use null coalescing operator ??=
$array = [];
-$array['user_id'] = $array['user_id'] ?? 'value';
+$array['user_id'] ??= 'value';
Add parentheses to nested ternary
-$value = $a ? $b : $a ?: null;
+$value = ($a ? $b : $a) ?: null;
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];
Turns defined function call new one.
-view("...", []);
+Laravel\Templating\render("...", []);