invenso / rector
Invenso Rector Bundle to update API Platform Annotations to Attributes
Installs: 42 553
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 4
Open Issues: 2
Requires
- php: ^8.0
- symfony/config: 5.4.* | ^6.0
- symfony/console: 5.4.* | ^6.0
- symfony/dependency-injection: 5.4.* | ^6.0
- symfony/http-kernel: 5.4.* | ^6.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.16
- phpstan/phpstan: ^1.10
- rector/rector: ^0.18.8
This package is auto-updated.
Last update: 2025-04-18 17:02:44 UTC
README
Invenso Rector can be used to convert Api Platform annotations to attributes
Since PHP version 8.0 annotations are replaced by using attributes
/** * @ApiResource */ class BookEntity { }
will be
#[ApiResource]
class BookEntity
{
}
Getting started
Requirement
- Api Platform must be installed
- Rector must be installed
Installation
Install the bundle by using composer
composer require invenso/rector
Configuration
The bundle can be configured by adding the configuration to the rector.php file
Add the following line to the rector file inside
$rectorConfig->sets([ ApiPlatformSetList::ANNOTATIONS_TO_ATTRIBUTES, ]);
Best practice is to have all ANNOTATIONS_TO_ATTRIBUTES converters present
$rectorConfig->sets([ DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES, DoctrineSetList::GEDMO_ANNOTATIONS_TO_ATTRIBUTES, ApiPlatformSetList::ANNOTATIONS_TO_ATTRIBUTES, SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES, SensiolabsSetList::ANNOTATIONS_TO_ATTRIBUTES, ]);
Execute Rector
Rector can be run by using the command
vendor/bin/rector process src
To make it a bit easier you can also add the rector command inside the composer.json file
{ ... "scripts": { "rector": "vendor/bin/rector" } }
Now you can run the following command to execute the rector script
composer rector process src