Skip to content

Report PHPStan attributes not covered by backward compatibility promise - #6916

Merged
ondrejmirtes merged 3 commits into
2.3.xfrom
api-attributes
Nov 2, 2026
Merged

ondrejmirtes merged 3 commits into
2.3.xfrom
api-attributes

Conversation

@ondrejmirtes

@ondrejmirtes ondrejmirtes commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

First step of #6283, done separately: AttributesCheck now reports using an attribute from the PHPStan\ namespace outside of PHPStan when the attribute class isn't @api, with the phpstanApi.attribute identifier. The message and tip match the other phpstanApi.* rules, and "outside of PHPStan" is decided by ApiRuleHelper::isPhpStanCode(). It's in AttributesCheck rather than a new rule, so it covers every attribute position. There's no bleeding-edge toggle because no existing code outside PHPStan uses PHPStan attributes yet.

@api attributes: Conditional, AutowiredService, NonAutowiredService, RegisteredRule, RegisteredCollector, GenerateFactory and AutowiredParameter. Their constructors are @api too. Otherwise ApiInstantiationRule reports new RegisteredRule(...) inside #[Conditional(...)].

Everything else, such as ContainerExtension, AutowiredExtensions, ExtensionInterface and ValidatesStubFiles, is reported.

Using an attribute from the PHPStan namespace outside of PHPStan is reported
with the phpstanApi.attribute identifier unless the attribute class has @api.
Conditional, AutowiredService, NonAutowiredService, RegisteredRule,
RegisteredCollector and GenerateFactory are @api, including their
constructors, so that new RegisteredRule(...) in Conditional's arguments
is not reported by ApiInstantiationRule.

Amp-Thread-ID: https://ampcode.com/threads/T-01a19cd4-be31-75b4-bd15-67786eff5983
@ondrejmirtes
ondrejmirtes merged commit 1ccb0c7 into 2.3.x Nov 2, 2026
33 checks passed
@ondrejmirtes
ondrejmirtes deleted the api-attributes branch November 2, 2026 18:10
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