Skip to content

[symfony] Add 6 generic PHPStan rules (attributes, DI, return shapes) - #285

Merged
TomasVotruba merged 4 commits into
mainfrom
tv/generic-attribute-di-rules
Sep 21, 2026
Merged

TomasVotruba merged 4 commits into
mainfrom
tv/generic-attribute-di-rules

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Adds 6 project-agnostic rules, extracted from a real Symfony/Doctrine app where they proved useful.

Symfony

  • CommandMustHaveAsCommandAttributeRule - a class extending Command must carry #[AsCommand].
  • ConstraintMustHaveAttributeRule - a class extending Constraint must carry #[\Attribute], so it works as a property attribute.
  • PreferInterfaceInConstructorRule - a constructor dependency typed as a concrete Symfony/Doctrine class that has a same-named *Interface should use the interface. Only 3rd-party (Symfony/Doctrine) types are checked; project classes are left alone.

General

  • NoDuplicateNonRepeatableAttributeRule - an attribute repeated on the same class/method/property must declare \Attribute::IS_REPEATABLE.
  • NoPropertyToPropertyAssignRule (Complexity) - $this->a = $this->b keeps the same service under 2 names; use the original directly.
  • RequireArrayShapeReturnRule - a method returning a packed keyed array of 2-3 named values should declare its @return array{...} shape.

Each rule is registered in the matching config set, documented in the README, and covered by a RuleTestCase with report + skip fixtures. Console/Validator stubs added for the attribute rules.

Note: AbstractClassNameMustBeAbstractRule from the same batch was intentionally dropped - ExplicitClassPrefixSuffixRule already covers a non-abstract Abstract* class.

Green locally: ECS, PHPStan, Rector, composer-dependency-analyser, full PHPUnit (349 tests).

…tructor, duplicate attribute, property-to-property assign, array-shape return
@TomasVotruba TomasVotruba changed the title Add 6 generic PHPStan rules (attributes, DI, return shapes) [symfony] Add 6 generic PHPStan rules (attributes, DI, return shapes) Sep 21, 2026
Co-authored-by: TomasVotruba <924196+TomasVotruba@users.noreply.github.com>
@TomasVotruba
TomasVotruba merged commit 807ec71 into main Sep 21, 2026
8 checks passed
@TomasVotruba
TomasVotruba deleted the tv/generic-attribute-di-rules branch September 21, 2026 08:14
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.

2 participants