Skip to content

Instantly share code, notes, and snippets.

@Exon0
Last active November 20, 2023 04:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Exon0/d5b8a4e2f7bb6f07d3031a4a66f5ddd0 to your computer and use it in GitHub Desktop.
Save Exon0/d5b8a4e2f7bb6f07d3031a4a66f5ddd0 to your computer and use it in GitHub Desktop.
Annotations to attributes symfony 5.4
Follow these steps to refactor annotations to attributes in a symfony 5.4+ project
### **Annotation to attribute steps:** ##
1) Install rector:
composer require rector/rector --dev
2) Create rector.php
vendor/bin/rector init
3) Add the following code to rector.php
```
use Rector\Doctrine\Set\DoctrineSetList;
use Rector\Php74\Rector\Property\TypedPropertyRector;
use Rector\Set\ValueObject\SetList;
use Rector\Config\RectorConfig;
use Rector\Symfony\Set\SymfonySetList;
return static function (RectorConfig $rectorConfig): void {
// here we can define, what sets of rules will be applied
// tip: use "SetList" class to autocomplete sets
$rectorConfig->sets([
SetList::CODE_QUALITY,
SensiolabsSetList::ANNOTATIONS_TO_ATTRIBUTES
DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES,
SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES,
SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION,
SymfonySetList::SYMFONY_CODE_QUALITY
]);
// register single rule
$rectorConfig->rule(TypedPropertyRector::class);
};
4) remove the starting semicolon ( ; ) from your xampp/php/php.ini
;extension=php_intl.dll
5) run refactor
vendor/bin/rector process
Reference : https://github.com/rectorphp/rector
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment