Skip to content

[Deprecation] Deprecate AutowireAttributeRector - #981

Merged
TomasVotruba merged 1 commit into
mainfrom
deprecate-autowire-attribute
Aug 2, 2026
Merged

[Deprecation] Deprecate AutowireAttributeRector#981
TomasVotruba merged 1 commit into
mainfrom
deprecate-autowire-attribute

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

AutowireAttributeRector scans every PHP config in a directory, collects service arguments, and then pairs them with constructor params by name and by position:

$currentEnv = $serviceArgument->getEnvs()[$constructorParameterName]
    ?? $serviceArgument->getEnvs()[$position]
    ?? null;

That guess is far-fetched and not reliable. A positional match across configs the rule cannot tell apart lands an #[Autowire] on the wrong param, and the attribute then silently wins over the config it was supposed to replace:

 final class SomeClass
 {
     public function __construct(
+        #[Autowire(param: 'timeout')]
         private int $timeout,
+        #[Autowire(env: 'APP_SECRET')]
         private string $secret,
     )  {
     }
 }

Right when the names line up, wrong as soon as they do not. Custom autowiring should be handled with care, one service at a time - not guessed in bulk.

What

  • The rule keeps its class and rule definition, implements DeprecatedInterface and throws on use, same as [Deprecation] Deprecate SimplifyFormRenderingRector #975.
  • Its tests are removed.
  • The config service argument resolving that only served this rule goes with it: ConfigServiceArgumentsResolver, SetServiceClassNameResolver, CollectServiceArgumentsNodeVisitor, ServiceArguments and NamedSimplePhpParser.

ParameterBagToAutowireAttributeRector is untouched - it reads the #[Autowire] target off an explicit $parameterBag->get('...') call, no guessing involved.

The rule pairs constructor params with config service arguments by name and
position, across every PHP config it finds. That guess is far-fetched and not
reliable, and custom autowiring should be handled with care, one service at a
time.

Removes the rule body, its tests and the config service argument resolving
that only served this rule.
@TomasVotruba
TomasVotruba merged commit 7467911 into main Aug 2, 2026
7 checks passed
@TomasVotruba
TomasVotruba deleted the deprecate-autowire-attribute branch August 2, 2026 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant