Skip to content

Match Symfony attributes by short name in StandaloneLineSymfonyAttributeParamFixer#60

Merged
TomasVotruba merged 2 commits into
mainfrom
match-symfony-attribute-short-name
Jul 22, 2026
Merged

Match Symfony attributes by short name in StandaloneLineSymfonyAttributeParamFixer#60
TomasVotruba merged 2 commits into
mainfrom
match-symfony-attribute-short-name

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Why

The fixer previously resolved each attribute's full class name via use statements (NamespaceUsesAnalyzer) before matching against a fully-qualified allowlist. That machinery is unnecessary — attribute short names (AsCommand, Route, Autowire, …) are already distinctive enough to match on directly.

What

  • Match by short name — the single T_STRING right before the attribute's (.
  • Works for both imported and fully-qualified usage, since the FQN's last name part is that same T_STRING.
  • Drops the NamespaceUsesAnalyzer dependency plus resolveShortNameToFullName() and resolveAttributeName().

Net: 31 insertions, 73 deletions.

Detection, before → after

-#[\Symfony\Component\Console\Attribute\AsCommand(name: 'app:x', description: 'y')]
+#[\Symfony\Component\Console\Attribute\AsCommand(
+    name: 'app:x',
+    description: 'y'
+)]

Same result whether the attribute is imported (#[AsCommand(...)]) or fully qualified (#[\Symfony\...\AsCommand(...)]).

Tests

Added Route and Autowire fixtures, each in imported and FQN variants, covering method-level and constructor-param-level attributes.

…uteParamFixer

Simplify attribute detection to match short names (AsCommand, Route, …)
instead of resolving full class names via use statements. Drops the
NamespaceUsesAnalyzer dependency and full-name resolution logic.
@TomasVotruba
TomasVotruba merged commit 0dc68f1 into main Jul 22, 2026
7 checks passed
@TomasVotruba
TomasVotruba deleted the match-symfony-attribute-short-name branch July 22, 2026 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant