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 old properties by new ones.
-$someObject->someOldProperty;
+$someObject->someNewProperty;
Change annotation to attribute
use Symfony\Component\Routing\Annotation\Route;
class SymfonyRoute
{
- /**
- * @Route("/path", name="action") api route
- */
+ #[Route(path: '/path', name: 'action')] // api route
public function action()
{
}
}
Add param types where needed
class SomeClass
{
- public function process($name)
+ public function process(string $name)
{
}
}
Migrates from deprecated Definition/Alias->setPrivate() to Definition/Alias->setPublic()
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\Definition;
class SomeClass
{
public function run()
{
$definition = new Definition('Example\Foo');
- $definition->setPrivate(false);
+ $definition->setPublic(true);
$alias = new Alias('Example\Foo');
- $alias->setPrivate(false);
+ $alias->setPublic(true);
}
}
Migrates from deprecated enable_magic_call_extraction context option in ReflectionExtractor
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
class SomeClass
{
public function run()
{
$reflectionExtractor = new ReflectionExtractor();
$readInfo = $reflectionExtractor->getReadInfo(Dummy::class, 'bar', [
- 'enable_magic_call_extraction' => true,
+ 'enable_magic_methods_extraction' => ReflectionExtractor::MAGIC_CALL | ReflectionExtractor::MAGIC_GET | ReflectionExtractor::MAGIC_SET,
]);
}
}
Migrates from deprecated ValidatorBuilder->enableAnnotationMapping($reader) to ValidatorBuilder->enableAnnotationMapping(true)->setDoctrineAnnotationReader($reader)
use Doctrine\Common\Annotations\Reader;
use Symfony\Component\Validator\ValidatorBuilder;
class SomeClass
{
public function run(ValidatorBuilder $builder, Reader $reader)
{
- $builder->enableAnnotationMapping($reader);
+ $builder->enableAnnotationMapping(true)->setDoctrineAnnotationReader($reader);
}
}
Migrates from deprecated Form Builder->setDataMapper(new PropertyPathMapper()) to Builder->setDataMapper(new DataMapper(new PropertyPathAccessor()))
use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper;
use Symfony\Component\Form\FormConfigBuilderInterface;
+use Symfony\Component\Form\Extension\Core\DataMapper\DataMapper;
+use Symfony\Component\Form\Extension\Core\DataAccessor\PropertyPathAccessor;
class SomeClass
{
public function run(FormConfigBuilderInterface $builder)
{
- $builder->setDataMapper(new PropertyPathMapper());
+ $builder->setDataMapper(new DataMapper(new PropertyPathAccessor()));
}
}
Change deprecated BinaryFileResponse::create() to use __construct() instead
use Symfony\Component\HttpFoundation;
class SomeClass
{
public function run()
{
- $binaryFile = BinaryFileResponse::create();
+ $binaryFile = new BinaryFileResponse(null);
}
}
Changes first argument of PropertyAccessor::__construct() to flags from boolean
class SomeClass
{
public function run()
{
- $propertyAccessor = new PropertyAccessor(true);
+ $propertyAccessor = new PropertyAccessor(PropertyAccessor::MAGIC_CALL | PropertyAccessor::MAGIC_GET | PropertyAccessor::MAGIC_SET);
}
}
Migrate from PropertyPathMapper to DataMapper and PropertyPathAccessor
use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper;
class SomeClass
{
public function run()
{
- return new PropertyPathMapper();
+ return new \Symfony\Component\Form\Extension\Core\DataMapper\DataMapper(new \Symfony\Component\Form\Extension\Core\DataAccessor\PropertyPathAccessor());
}
}