invenso/rector

Invenso Rector Bundle to update API Platform Annotations to Attributes

1.0.2 2024-01-18 14:13 UTC

This package is auto-updated.

Last update: 2024-09-18 15:52:13 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

Rector documentation

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