Find the best Rector rule to solve your problem. Searching through 775 rules.
Found 11 rules:
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');
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 @deprecated annotation to Deprecated attribute
-/**
- * @deprecated 1.0.0 Use SomeOtherConstant instead
- */
+#[\Deprecated(message: 'Use SomeOtherConstant instead', since: '1.0.0')]
const SomeConstant = 'irrelevant';
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_first($array);
+echo array_last($array;