Skip to content
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

ClassMustBeFinal: BC break #11288

Closed
Ocramius opened this issue Feb 16, 2025 · 7 comments
Closed

ClassMustBeFinal: BC break #11288

Ocramius opened this issue Feb 16, 2025 · 7 comments

Comments

@Ocramius
Copy link
Contributor

Looking at various composer.lock upgrades from last night:

Although I violently agree with making things final, vimeo/psalm:6.6.0 introduced a breaking change in what's considered valid and not (and it's not just a shift due to type refinements):

https://psalm.dev/docs/annotating_code/supported_annotations/#api-psalm-api

Specifically, it seems like Psalm now requires things to be marked as API, whilst, tbh, that's only a Symfony thing.
The rest of us uses @internal for what isn't @api: see for example https://github.com/Roave/BackwardCompatibilityCheck/blob/448b845a54afd41a54d93c4403900211abda4b3c/src/DetectChanges/BCBreak/ClassBased/MethodRemoved.php#L61-L66

Unless I'm misunderstanding something, I'd recommend having the default psalm profile not having this requirement, and requiring to do so in a new major version, if it's a design decision.

If @api is only used for discovering unused code, then I'm fine with it: at least tests should be written, but in such case, the error message reporting ClassMustBeFinal is probably wrong.

@Ocramius
Copy link
Contributor Author

Also, to clarify: I agree that this is a good change, just not with how it was introduced, if it was intentional.

@danog
Copy link
Collaborator

danog commented Feb 16, 2025

The requirement to explicitly use @apior @internal is something that was already present in Psalm v6 due to unused code detection being turned on by default.

Generally, I do not consider the addition of issues (& the requirement to change some code due to their addition) to be a breaking change for Psalm: in fact, I'm preparing #11283 which will turn on a lot of previously hidden features in a minor (feature) tag, which makes sense because minors are for new features, and new features in Psalm inherently mean more issues.

@danog danog closed this as completed Feb 16, 2025
@Ocramius
Copy link
Contributor Author

Ocramius commented Feb 16, 2025

I would advise against that: from a maintainer PoV that uses Psalm, this will just mean that every psalm update is a major version.

This already happens with PHP itself, and it hurts, a lot, every year.

It's fine if you declare it as such (by releasing major SemVer versions), but please do consider BC boundaries for your libraries/tools carefully, because this really hurts people that put some real effort in both advocating for psalm, and making codebases as bug-free as possible.

If you do not have BC boundaries of any type here, and things like #11283 become the norm, then I'm OK with migrating my OSS projects to PHPStan, with some effort, and I'm not really happy to do so either, since I firmly believe that psalm has an edge in taint and purity analysis.

@danog
Copy link
Collaborator

danog commented Feb 16, 2025

This was never the case with Psalm, new issues were always introduced in minors, never in majors: majors were only used for major API changes (which affect plugins).

I understand phpstan uses a different approach with bleeding edge, but this was never the case with Psalm, and I see no reason to change this.

@Ocramius
Copy link
Contributor Author

Fair enough, perhaps we got spoiled by a long period of seeming stability and bugfixing-only.

@iquito
Copy link

iquito commented Feb 16, 2025

@Ocramius You can just suppress this new issue in the psalm config (link to documentation). Personally I don't think this new issue makes much sense for libraries (and should be suppressed, which I will do, rather than be forced to put final and @api everywhere), while it does usually make sense for applications.

(I would prefer if such new issues were introduced as opt-in rather than opt-out too, though, such that projects are not surprised by new issues in possibly every new minor version - seems fragile)

@Ocramius
Copy link
Contributor Author

@iquito I'm well aware that there's:

  • suppressing
  • baselining
  • spreading @api like dung on a field

The problem is mostly the direction that is being taken, which worries me much more: this issue is a data point.

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

No branches or pull requests

3 participants