skip to Main Content

i want to use Rector for refactoring my code because i update my project to symfony 5.4 to 6.1.
My php project version : 8.1.5

So, i want to use a simple rule who change my annotation to attribut with rector. but when i execute rector with command : vendor/bin/rector process src

rector inform me : [OK] Rector is done!

But my file don’t change, my entity annotation don’t change.
i try to follow this documentation for config my rector.php and use rector with symfony.

https://github.com/rectorphp/rector-symfony

https://github.com/rectorphp/rector

what i do wrong ?

this is my rector.php

<?php

declare(strict_types=1);

use RectorConfigRectorConfig;
use RectorPhp80ValueObjectAnnotationToAttribute;
use RectorPhp80RectorClass_AnnotationToAttributeRector;
use RectorSymfonyRectorMethodCallStringFormTypeToClassRector;
use RectorSymfonyRectorClass_CommandPropertyToAttributeRector;

return static function (RectorConfig $rectorConfig): void {
    $rectorConfig->paths([
        __DIR__ . '/src'
    ]);

    $rectorConfig->phpstanConfig(__DIR__ . '/phpstan.neon');

    $rectorConfig->symfonyContainerXml(__DIR__ . '/var/cache/dev/App_KernelDevDebugContainer.xml');

    
    $rectorConfig->ruleWithConfiguration(
      AnnotationToAttributeRector::class,
      [new AnnotationToAttribute('SymfonyRoutingAnnotationRoute')]
  );
    // register a single rule
    //$rectorConfig->rule(CommandPropertyToAttributeRector::class);

    // define sets of rules
      /* $rectorConfig->sets([
        SymfonySetList::SYMFONY_60,
        SymfonySetList::SYMFONY_CODE_QUALITY,
        SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION,
        ]);*/
};

this is my composer.json


{
    "type": "project",
    "license": "proprietary",
    "minimum-stability": "dev",
    "prefer-stable": true,
    "require": {
        "php": ">=7.2.5",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "composer/package-versions-deprecated": "1.11.99.1",
        "doctrine/annotations": "^1.12",
        "doctrine/dbal": "^2.0",
        "doctrine/doctrine-bundle": "^2.2",
        "doctrine/doctrine-fixtures-bundle": "^3.4",
        "doctrine/doctrine-migrations-bundle": "^3.0",
        "doctrine/orm": "^2.8",
        "fakerphp/faker": "^1.19",
        "gedmo/doctrine-extensions": "^3.8",
        "giggsey/libphonenumber-for-php": "^8.12",
        "knplabs/knp-paginator-bundle": "^5.3",
        "phpdocumentor/reflection-docblock": "^5.2",
        "sensio/framework-extra-bundle": "^6.2",
        "symfony/asset": "6.1.*",
        "symfony/console": "6.1.*",
        "symfony/doctrine-bridge": "6.1.*",
        "symfony/dotenv": "6.1.*",
        "symfony/expression-language": "6.1.*",
        "symfony/flex": "^1.3.1",
        "symfony/form": "6.1.*",
        "symfony/framework-bundle": "6.1.*",
        "symfony/http-client": "6.1.*",
        "symfony/http-foundation": "6.1.*",
        "symfony/intl": "6.1.*",
        "symfony/mailer": "6.1.*",
        "symfony/mime": "6.1.*",
        "symfony/monolog-bundle": "^3.1",
        "symfony/notifier": "6.1.*",
        "symfony/options-resolver": "6.1.*",
        "symfony/process": "6.1.*",
        "symfony/property-access": "6.1.*",
        "symfony/property-info": "5.4.*",
        "symfony/proxy-manager-bridge": "6.1.*",
        "symfony/rate-limiter": "6.1.*",
        "symfony/runtime": "6.1.*",
        "symfony/security-bundle": "6.1.*",
        "symfony/serializer": "6.1.*",
        "symfony/string": "6.1.*",
        "symfony/translation": "6.1.*",
        "symfony/twig-bundle": "6.1.*",
        "symfony/validator": "6.1.*",
        "symfony/web-link": "6.1.*",
        "symfony/webpack-encore-bundle": "^1.14",
        "symfony/yaml": "6.0.*",
        "twig/extra-bundle": "^2.12|^3.0",
        "twig/twig": "^2.12|^3.0"
    },
    "require-dev": {
        "fakerphp/faker": "^1.19",
        "phpstan/phpstan": "^1.8",
        "phpstan/phpstan-doctrine": "^1.3",
        "rector/rector": "^0.13.9",
        "symfony/browser-kit": "6.1.*",
        "symfony/css-selector": "6.1.*",
        "symfony/debug-bundle": "6.1.*",
        "symfony/maker-bundle": "^1.30",
        "symfony/phpunit-bridge": "6.1.*",
        "symfony/stopwatch": "6.1.*",
        "symfony/var-dumper": "6.1.*",
        "symfony/web-profiler-bundle": "6.1.*"
    },

Thanks for your help !

4

Answers


  1. Chosen as BEST ANSWER

    So, the problem here is the version of php in composer.json

    we just need to change php version 7 to 8

    "php": ">=7.2.5" to "php": "^8.0"

    Bye


  2. I am not sure why exactly but for me the solution was to remove the path config:

    $rectorConfig->paths([
        __DIR__ . '/src'
    ]);
    

    and only use the path as an argument to the binary call:

    php vendor/bin/rector process <PATH>

    Login or Signup to reply.
  3. It is working for me:

    use RectorSymfonySetSymfonySetList;
    use RectorConfigRectorConfig;
    use RectorDoctrineSetDoctrineSetList;
    use RectorSymfonySetSensiolabsSetList;
    use RectorSetValueObjectSetList;
    
    return static function (RectorConfig $rectorConfig): void {
        $rectorConfig->paths([
            __DIR__ . '/src'
        ]);
        $rectorConfig->symfonyContainerXml(__DIR__ . '/var/cache/dev/App_KernelDevDebugContainer.xml');
        $rectorConfig->sets([
            SymfonySetList::SYMFONY_60,
            SymfonySetList::SYMFONY_CODE_QUALITY,
            SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION
        ]);
        
        $rectorConfig->sets([
            DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES,
            SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES,
            SensiolabsSetList::FRAMEWORK_EXTRA_61 
           
        ]);
    
    
    };
    
    Login or Signup to reply.
  4. Clearing the rector cache worked for me:

    vendor/bin/rector process --clear-cache --dry-run
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search