You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Follow-up to #6018. A method marked @pure-unless-parameter-passed tells callers it is pure as long as the flagged out parameter is omitted, but an override marked @phpstan-impure can break that without any error. @pure-unless-callable-is-impure already has this check (method.impureOverridePureUnlessCallable); this adds the same for the new tag.
Changes
MethodSignatureRule reports Impure method %s::%s() overrides method %s::%s() marked @pure-unless-parameter-passed. with the identifier method.impureOverridePureUnlessParameterPassed.
Like the existing check, it only runs with reportMethodPurityOverride (bleeding edge) and only for an override that is explicitly impure; an override without a purity tag or one marked @phpstan-pure is not reported.
When the parent carries both tags, only the @pure-unless-callable-is-impure error is reported, so each parent method still yields at most one error.
Not in this PR: the signature checks in FunctionPurityCheck (e.g. a non-optional parameter marked @pure-unless-parameter-passed) only run for methods with a body, so interface and abstract methods aren't checked. That applies to the existing @phpstan-pure checks as well, so I'd handle it separately.
I added this in 6fa0be6. PHPStan reports an implementation in a @phpstan-all-methods-impure class the same way as one marked @phpstan-impure, and leaves one in a @phpstan-all-methods-pure class alone.
I left out the other direction, a @phpstan-all-methods-pure class that declares the @pure-unless-parameter-passed method itself, because PHPStan gets that case wrong: it lets the class-level tag override the method's own tag and treats the method as unconditionally pure. It then misses a caller that passes $count, and reports an impure override as method.impure ("overrides pure method") instead of the new error. @pure-unless-callable-is-impure on 2.3.x has the same problem: in such a class, PHPStan misses an impure callback too. I'll fix both tags in a separate PR.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #6018. A method marked
@pure-unless-parameter-passedtells callers it is pure as long as the flagged out parameter is omitted, but an override marked@phpstan-impurecan break that without any error.@pure-unless-callable-is-impurealready has this check (method.impureOverridePureUnlessCallable); this adds the same for the new tag.Changes
MethodSignatureRulereportsImpure method %s::%s() overrides method %s::%s() marked @pure-unless-parameter-passed.with the identifiermethod.impureOverridePureUnlessParameterPassed.reportMethodPurityOverride(bleeding edge) and only for an override that is explicitly impure; an override without a purity tag or one marked@phpstan-pureis not reported.@pure-unless-callable-is-impureerror is reported, so each parent method still yields at most one error.Not in this PR: the signature checks in
FunctionPurityCheck(e.g. a non-optional parameter marked@pure-unless-parameter-passed) only run for methods with a body, so interface and abstract methods aren't checked. That applies to the existing@phpstan-purechecks as well, so I'd handle it separately.