Skip to content

Recognize imported short-name Symfony attributes#57

Merged
TomasVotruba merged 1 commit into
mainfrom
symfony-attr-imported-name-support
Jul 22, 2026
Merged

Recognize imported short-name Symfony attributes#57
TomasVotruba merged 1 commit into
mainfrom
symfony-attr-imported-name-support

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Recognize imported short-name Symfony attributes

Follow-up to #56. StandaloneLineSymfonyAttributeParamFixer previously only matched attributes written with a fully-qualified name. It now also resolves short names against the file's use statements, so imported Symfony attributes are handled too.

 use Symfony\Component\Console\Attribute\AsCommand;

-#[AsCommand(name: 'app:some', description: 'Some description')]
+#[AsCommand(
+    name: 'app:some',
+    description: 'Some description'
+)]
 final class SomeCommand
 {
 }

Still matched: fully-qualified #[\Symfony\...\AsCommand(...)].
Still skipped: non-Symfony attributes, whether fully-qualified (#[\Doctrine\ORM\Mapping\Table(...)]) or imported (use Doctrine\ORM\Mapping\Table; #[Table(...)]), argument-less attributes, and empty argument lists.

How detection works

  1. If the written name contains Symfony → match (covers FQCN and partially-qualified).
  2. Else if it is fully-qualified (leading \) → skip.
  3. Else resolve its first segment via the file's use imports; match when the resolved FQCN contains Symfony.

…fonyAttributeParamFixer

Resolve the attribute name via file use statements so short names like
#[AsCommand(...)] imported from Symfony are handled, not only the
fully-qualified #[\Symfony\...\AsCommand(...)] form.
@TomasVotruba
TomasVotruba enabled auto-merge (squash) July 22, 2026 13:53
@TomasVotruba
TomasVotruba disabled auto-merge July 22, 2026 13:54
@TomasVotruba
TomasVotruba merged commit b5d19ed into main Jul 22, 2026
8 checks passed
@TomasVotruba
TomasVotruba deleted the symfony-attr-imported-name-support branch July 22, 2026 13:54
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