Skip to content

Add support for psalm-inheritors and phpstan-sealed tag #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 13, 2025

Conversation

VincentLanglet
Copy link
Contributor

Needed to implements the following feature on phpstan side
https://psalm.dev/docs/annotating_code/supported_annotations/#psalm-inheritors

@ondrejmirtes
Copy link
Member

I’d prefer a different name for the PHPStan tag.

some keywords to consider:

  • subclass
  • subtype
  • implementation
  • allowed subclass
  • Allowed subtype

What are your suggestions?

@VincentLanglet
Copy link
Contributor Author

I checked all the possibility and psalm supports them
https://psalm.dev/r/8a398e4a93

I’d prefer a different name for the PHPStan tag.

some keywords to consider:

  • subclass
  • subtype
  • implementation
  • allowed subclass
  • Allowed subtype

What are your suggestions?

Since it works for interface too ; I would not use the subclass word.
Since it works for extends too ; I would not use the implementation word.

So I would say something like

@phpstan-subtypes
@phpstan-allowed-subtypes
@phpstan-restricted-subtypes
@phpstan-children
@phpstan-allowed-children
@phpstan-restricted-children

@phpstan-subtypes might be the simplest/shortest.

But if we look at other languages (and the related php rfc https://wiki.php.net/rfc/sealed_classes), seems adding a
@psalm-inheritors means

  • The class/interface is sealed
  • The permitted extensions are the one listed

Therefor maybe something like @phpstan-sealed Foo|Bar or @phpstan-permits Foo|Bar ?

Or @phpstan-permitted-subtypes then ?

Does anything satisfy you @ondrejmirtes ?

@ondrejmirtes
Copy link
Member

@phpstan-allowed-subtypes or @phpstan-sealed might be the best in line with https://phpstan.org/developing-extensions/allowed-subtypes and https://github.com/jiripudil/phpstan-sealed-classes. I like the sealed better.

@ondrejmirtes
Copy link
Member

Of course Phpstan should understand psalm inheritors too.

@VincentLanglet VincentLanglet changed the title Add support for psalm-inheritors and phpstan-inheritors tag Add support for psalm-inheritors and phpstan-sealed tag Jul 12, 2025
@VincentLanglet
Copy link
Contributor Author

I like the sealed better.

Done with @phpstan-sealed then

@VincentLanglet
Copy link
Contributor Author

The

[Test Slevomat Coding Standard / Tests (8.4) (pull_request)](https://github.com/phpstan/phpdoc-parser/actions/runs/16237681772/job/45849904924?pr=273)Failing after 26s

is failing because of php deprecation on PHPUnit 10.5.11.

The dev-dependency was bumped on slevomat coding standard in commit 4747e312a24d4827b1d090b5908c7d5b16cf0580
Should I bump the commit in the github actions ?

@ondrejmirtes
Copy link
Member

@VincentLanglet Yes, in a separate PR please.

@ondrejmirtes ondrejmirtes merged commit 375fc54 into phpstan:2.1.x Jul 13, 2025
43 of 44 checks passed
@ondrejmirtes
Copy link
Member

Thank you! Please send a PR to phpstan-src as well.

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