skip to Main Content

As Doctrine seems to have completely removed annotations support in their latest updates, I am trying to convert the annotations in my entities to attributes using Rector.

I followed the (seemingly) simple official tutorial – I have the exact same rector.php contents, without the NetteSetList:

use RectorDoctrineSetDoctrineSetList;
use RectorSymfonySetSymfonySetList;
use RectorSymfonySetSensiolabsSetList;
use RectorConfigRectorConfig;

return function (RectorConfig $rectorConfig): void {
    $rectorConfig->sets([
        DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES,
        SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES,
        SensiolabsSetList::FRAMEWORK_EXTRA_61,
    ]);
};

I run the test with vendor/bin/rector process src/Entity --dry-run --debug.

It does list every single entity in src/Entity, but does not detect any possible changes, when it should replace every doctrine annotation with attributes.

2

Answers


  1. Do you perhaps use PHPStan? It seems that the phpstan.neon config file is automatically used by Rector, whether you tell it to or not.

    I did the following

    • remove phpstan.neon file from project root dir
    • run Rector again with the --clear-cache option. It doesn’t seem to recognize the config change in phpstan.neon without it.

    And now Rector suggests changes again.

    It seems to have something to do with the scanFiles option in phpstan.neon. In our case it had an entry to to fix issues where PHPCS enforces the use of global constants in custom sniffs.

    parameters:
        scanFiles:
            - vendor/squizlabs/php_codesniffer/src/Util/Tokens.php
    

    I don’t have further details yet. But perhaps this might help you out.

    Login or Signup to reply.
  2. I had the same problem, and I solve it by changing the version of Php in composer.json as explained here:
    Configure Rector and using a simple Rule with symfony 6/php8

    Just need to change php version 7 to 8
    "php": ">=7.2.5" to "php": "^8.0"

    I hope this help 🙂

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search