rectorphp / rector-symfony

Rector upgrade rules for Symfony
http://getrector.com
MIT License
179 stars 86 forks source link

[Symfony 6.3] Add ParamAndEnvAttributeRector #641

Closed TomasVotruba closed 2 months ago

TomasVotruba commented 2 months ago

Symfony 6.3 introduced tiny improvement to use param and env directly as named argument of #[Attribute].

See https://symfony.com/blog/new-in-symfony-6-3-dependency-injection-improvements#new-options-for-autowire-attribute

Here we go :)

 namespace App\Service;

 use Symfony\Component\DependencyInjection\Attribute\Autowire;

 class MessageGenerator
 {
     public function __construct(
-        #[Autowire('%kernel.debug%')]
+        #[Autowire(param: 'kernel.debug')]
         bool $debugMode,

-        #[Autowire('%env(SOME_ENV_VAR)%')]
+        #[Autowire(env: 'SOME_ENV_VAR')]
         string $senderName,
     ) {
     }
 }