Find the best Rector rule to solve your problem


Configurable

RenameClassConstFetchRector

Replaces defined class constants in their calls.

-$value = SomeClass::OLD_CONSTANT;
-$value = SomeClass::OTHER_OLD_CONSTANT;
+$value = SomeClass::NEW_CONSTANT;
+$value = DifferentClass::NEW_CONSTANT;

Configurable

RenameClassRector

Replaces defined classes by new ones.

 namespace App;

-use SomeOldClass;
+use SomeNewClass;

-function someFunction(SomeOldClass $someOldClass): SomeOldClass
+function someFunction(SomeNewClass $someOldClass): SomeNewClass
 {
-    if ($someOldClass instanceof SomeOldClass) {
-        return new SomeOldClass;
+    if ($someOldClass instanceof SomeNewClass) {
+        return new SomeNewClass;
     }
 }

SwiftSetBodyToHtmlPlainMethodCallRector

Changes setBody() method call on Swift_Message into a html() or plain() based on second argument

 $message = new Swift_Message();

-$message->setBody('...', 'text/html');
+$message->html('...');

-$message->setBody('...', 'text/plain');
-$message->setBody('...');
+$message->text('...');
+$message->text('...');

SwiftCreateMessageToNewEmailRector

Changes createMessage() into a new Symfony\Component\Mime\Email

-$email = $this->swift->createMessage('message');
+$email = new \Symfony\Component\Mime\Email();

SwiftMessageToEmailRector

Convert \Swift_Message into an \Symfony\Component\Mime\Email

-$message = (new \Swift_Message('Hello Email'))
-        ->setFrom('send@example.com')
-        ->setTo(['recipient@example.com' => 'Recipient'])
-        ->setBody(
-            $this->renderView(
-                'emails/registration.html.twig',
-                ['name' => $name]
-            ),
-            'text/html'
-        )
+$message = (new Email())
+    ->from(new Address('send@example.com'))
+    ->to(new Address('recipient@example.com', 'Recipient'))
+    ->subject('Hello Email')
+    ->html($this->renderView(
+        'emails/registration.html.twig',
+        ['name' => $name]
+    ))
+;