Find the best Rector rule to solve your problem
Turns method names to new ones.
$someObject = new SomeExampleClass;
-$someObject->oldMethod();
+$someObject->newMethod();
Replaces defined class constants in their calls.
-$value = SomeClass::OLD_CONSTANT;
-$value = SomeClass::OTHER_OLD_CONSTANT;
+$value = SomeClass::NEW_CONSTANT;
+$value = DifferentClass::NEW_CONSTANT;
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;
}
}
Turns old option names to new ones in FormTypes in Form in Symfony
$builder = new FormBuilder;
-$builder->add("...", ["precision" => "...", "virtual" => "..."];
+$builder->add("...", ["scale" => "...", "inherit_data" => "..."];
Turns string Form Type references to their CONSTANT alternatives in FormTypes in Form in Symfony. To enable custom types, add link to your container XML dump in "$rectorConfig->symfonyContainerXml(...)"
$formBuilder = new Symfony\Component\Form\FormBuilder;
-$formBuilder->add('name', 'form.type.text');
+$formBuilder->add('name', \Symfony\Component\Form\Extension\Core\Type\TextType::class);
Change type in CollectionType from alias string to class reference
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
class TaskType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('tags', CollectionType::class, [
- 'type' => 'choice',
+ 'type' => \Symfony\Component\Form\Extension\Core\Type\ChoiceType::class,
]);
$builder->add('tags', 'collection', [
- 'type' => 'choice',
+ 'type' => \Symfony\Component\Form\Extension\Core\Type\ChoiceType::class,
]);
}
}
Changes createForm(new FormType), add(new FormType) to ones with "FormType::class"
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
final class SomeController extends Controller
{
public function action()
{
- $form = $this->createForm(new TeamType);
+ $form = $this->createForm(TeamType::class);
}
}
Change "read_only" option in form to attribute
use Symfony\Component\Form\FormBuilderInterface;
function buildForm(FormBuilderInterface $builder, array $options)
{
- $builder->add('cuid', TextType::class, ['read_only' => true]);
+ $builder->add('cuid', TextType::class, ['attr' => ['read_only' => true]]);
}
Rename getBlockPrefix()
if it returns the default value - class to underscore, e.g. UserFormType = user_form
use Symfony\Component\Form\AbstractType;
class TaskType extends AbstractType
{
- public function getBlockPrefix()
- {
- return 'task';
- }
}
Turns string Form Type references to their CONSTANT alternatives in getParent()
and getExtendedType()
methods in Form in Symfony
use Symfony\Component\Form\AbstractType;
class SomeType extends AbstractType
{
public function getParent()
{
- return 'collection';
+ return \Symfony\Component\Form\Extension\Core\Type\CollectionType::class;
}
}
Turns fetching of Request via $this->getRequest()
to action injection
+use Symfony\Component\HttpFoundation\Request;
+
class SomeController
{
- public function someAction()
+ public function someAction(Request $request)
{
- $this->getRequest()->...();
+ $request->...();
}
}