rectorphp/rector-symfony

Bug on AnnotationToAttribute ?

mauriau opened this issue ยท 4 comments

Hi,

I have some old annotations on my Symfony app. So, I want to convert them to attribute.
I'm on Symfony 6.3 and PHP8.1

In my rector file, I put this :

I also tested it with SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES, but it changed nothing

return function (RectorConfig $rectorConfig): void {
    $rectorConfig->symfonyContainerXml(__DIR__.'/var/cache/dev/App_KernelDevDebugContainer.xml');
    $rectorConfig->ruleWithConfiguration(AnnotationToAttributeRector::class, [
        new AnnotationToAttribute('Symfony\Component\Routing\Annotation\Route'),
    ]);
};

Then, I run rector on only one file, but nothing happened
vendor/bin/rector process --clear-cache src/Controller/Admin/Framework/EntityTagController.php


src/Controller/Admin/Framework/EntityTagController.php
[file] src/Controller/Admin/Framework/EntityTagController.php
[rule] Rector\Php80\Rector\Class_\AnnotationToAttributeRector
--- consumed 0 B, total 80 MB, took 0.01 s

[file] src/Controller/Admin/Framework/EntityTagController.php
[rule] Rector\Php80\Rector\Class_\AnnotationToAttributeRector
--- consumed 0 B, total 80 MB, took 0.00 s

[file] src/Controller/Admin/Framework/EntityTagController.php
[rule] Rector\Php80\Rector\Class_\AnnotationToAttributeRector
--- consumed 0 B, total 80 MB, took 0.00 s

[file] src/Controller/Admin/Framework/EntityTagController.php
[rule] Rector\Php80\Rector\Class_\AnnotationToAttributeRector
--- consumed 0 B, total 80 MB, took 0.00 s

[file] src/Controller/Admin/Framework/EntityTagController.php
[rule] Rector\Php80\Rector\Class_\AnnotationToAttributeRector
--- consumed 0 B, total 80 MB, took 0.00 s

[file] src/Controller/Admin/Framework/EntityTagController.php
[rule] Rector\Php80\Rector\Class_\AnnotationToAttributeRector
--- consumed 0 B, total 80 MB, took 0.00 s

[file] src/Controller/Admin/Framework/EntityTagController.php
[rule] Rector\Php80\Rector\Class_\AnnotationToAttributeRector
--- consumed 0 B, total 80 MB, took 0.00 s

[file] src/Controller/Admin/Framework/EntityTagController.php
[rule] Rector\Php80\Rector\Class_\AnnotationToAttributeRector
--- consumed 0 B, total 80 MB, took 0.00 s


In my file (EntityTagController), got these annotations

/**
 * @ParamConverter("project", options={"mapping": {"projectId": "id"}})
 * @IsGranted("edit", subject="project")
 */

I don't understand why nothing happened, can someone help me ?

Those annotations are not part of that set list ๐Ÿ™‚

For @ParamConverter you need ParamConverterAttributeToMapEntityAttributeRector::class (which is part of the Symfony 6.2 set).

Since you mention you are currently on Symfony 6.3, I'd suggest you use the SymfonyLevelSetList::UP_TO_SYMFONY_63 set list:

use Rector\Symfony\Set\SymfonyLevelSetList;

return static function (RectorConfig $rectorConfig): void {
    $rectorConfig->sets([SymfonyLevelSetList::UP_TO_SYMFONY_63]);
};

I am closing it since the solution provided above #499 (comment)

Yeah, it's ok. I Re run rector step by step from 6.0 to 6.3.
By changging rules UP_TO_SYMFONY_60, run rector, then UP_TO_SYMFONY_61, run rector etc etc. And it's migrate well