Find a Rector rule

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

Found 10 rules, grouped by set: Clear

Not in a set 10 matches

Downgrade hash algorithm xxh32, xxh64, xxh3 or xxh128 by default to md5. You can configure the algorithm to downgrade.

 class SomeClass
 {
     public function run()
     {
-        return hash('xxh128', 'some-data-to-hash');
+        return hash('md5', 'some-data-to-hash');
     }
 }

Downgrade Symfony Command Attribute

 #[AsCommand(name: 'app:create-user', description: 'some description')]
 class CreateUserCommand extends Command
 {
+    protected function configure(): void
+    {
+        $this->setName('app:create-user');
+        $this->setDescription('some description');
+    }
 }

Downgrade standalone return null, true, or false

 final class SomeClass
 {
-    public function run(): null
+    public function run(): mixed
     {
         return null;
     }
 }

Downgrade ReflectionMethod::hasPrototype() by emulating it with getPrototype()

 class SomeClass
 {
     public function run(ReflectionMethod $reflectionMethod): bool
     {
-        return $reflectionMethod->hasPrototype();
+        return (function (\ReflectionMethod $reflectionMethod2): bool {
+            try {
+                $reflectionMethod2->getPrototype();
+                return true;
+            } catch (\ReflectionException) {
+                return false;
+            }
+        })($reflectionMethod);
     }
 }

Ensure pass Traversable instance before use in iterator_count() and iterator_to_array()

 function test(array|Traversable $data) {
-    $c = iterator_count($data);
-    $v = iterator_to_array($data);
+    $c = iterator_count(is_array($data) ? new ArrayIterator($data) : $data);
+    $v = iterator_to_array(is_array($data) ? new ArrayIterator($data) : $data);
 }

Remove "never" return type from arrow functions, which PHP 8.1 rejects at compile time

-$callable = fn (): never => throw new \RuntimeException();
+$callable = fn () => throw new \RuntimeException();

Remove the union type with intersection, use docblock based

 final class SomeClass
 {
-    public (A&B)|C $foo;
+    /**
+     * @var (A&B)|C
+     */
+    public $foo;
 }

Remove "readonly" class type, decorate all properties to "readonly"

-final readonly class SomeClass
+final class SomeClass
 {
-    public string $foo;
+    public readonly string $foo;

     public function __construct()
     {
         $this->foo = 'foo';
     }
 }

Downgrade previously implemented interface

 interface ContainerExceptionInterface extends Throwable
 {
 }

-interface ExceptionInterface extends ContainerExceptionInterface, Throwable
+interface ExceptionInterface extends ContainerExceptionInterface
 {
 }

Downgrade reflection $reflection->getType() method call

 class SomeClass
 {
     public function run(ReflectionProperty $reflectionProperty)
     {
-        if ($reflectionProperty->getType()) {
+        if (method_exists($reflectionProperty, 'getType') ? $reflectionProperty->getType() ? null) {
             return true;
         }

         return false;
     }
 }