Rector Rules for BEAR.Sunday
The rector/rector rules for BEAR.Sunday.
Install
composer require bearsunday/rector-bearsunday 1.x-dev --dev
Use Sets
// rector.php
use Rector\BearSunday\RayDiNamedAnnotation\Rector\ClassMethod\RayDiNamedAnnotationRector;
use Rector\Core\Configuration\Option;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
require __DIR__ . '/vendor/autoload.php';
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
$services->set(RayDiNamedAnnotationRector::class);
};
See Auto Import Names for Option::AUTO_IMPORT_NAME
.
Rules
RayDiNamedAnnotationRector
Change @Named
annotation in method to #[Named]
attribute in parameter.
- class:
RayDiNamedAnnotationRector
class SomeClass
{
/**
- * @Named("a=foo, b=bar")
* @Foo
*/
- public function __construct(int $a, int $b)
+ public function __construct(#[Named('foo')] int $a, #[Named('bar')] int $b)
{
}