Find a Rector rule

Find the best Rector rule to solve your problem. Searching through 1005 rules.

Found 11 rules, grouped by set: Clear

PHP 8.5 11 matches

Replace null key in array_key_exists with empty string

-array_key_exists(null, $array);
+array_key_exists('', $array);

Wrap chr() argument with % 256 to avoid deprecated out-of-range integers

-echo chr(300);
+echo chr(300 % 256);

Remove argument by position by function name

-finfo_buffer($finfo, $fileContents, FILEINFO_NONE, []);
+finfo_buffer($finfo, $fileContents, FILEINFO_NONE);

Replace ord($str) with ord($str[0])

-echo ord('abc');
+echo ord('a');

Add override attribute to overridden properties

 class ParentClass
 {
     public string $name;
 }

 final class ChildClass extends ParentClass
 {
+    #[\Override]
     public string $name;
 }

Change deprecated semicolon to colon after switch case

 switch ($value) {
-    case 'baz';
+    case 'baz':
         echo 'baz';
 }

Replace backticks based with shell_exec() function calls

-$output = `ls -al`;
+$output = shell_exec('ls -al');
 echo "<pre>$output</pre>";

Change __wakeup() to __unserialize()

 class User {
-    public function __wakeup() {
+    public function __unserialize(array $data): void{
+        foreach ($data as $property => $value) {
+            if (property_exists($this, $property)) {
+                $this->{$property} = $value;
+            }
+        }
     }
 }

Change __sleep() to __serialize() with correct return values

 class User {
     private $id;
     private $name;

-    public function __sleep() {
-        return ['id', 'name'];
+    public function __serialize(): array {
+        return [
+            'id' => $this->id,
+            'name' => $this->name,
+        ];
     }
 }

Replaces null return value with empty array in __debugInfo methods

 new class
 {
     public function __debugInfo() {
-        return null;
+        return [];
     }
 };

Make use of array_first() and array_last()

-echo $array[array_key_first($array)];
-echo $array[array_key_last($array)];
-echo array_values($array)[0];
-echo array_values($array)[count($array) - 1];
+echo array_first($array);
+echo array_last($array);
+echo array_first($array);
+echo array_last($array);