Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 #6669, which leaves this case out. A docblock that marks a function or method
@phpstan-pureor@phpstan-impureand also makes its purity conditional with@pure-unless-callable-is-impureor@pure-unless-parameter-passedcontradicts itself, and PHPStan follows a different tag depending on where it looks:With
@phpstan-impure, callers see an impure function, sinceSimpleImpurePoint::createFromVariant()skips the conditional verdict onceisPure()is no, whileFunctionPurityCheckchecks the body against the conditional tag and reports theecho.With
@phpstan-pure, callers see an unconditionally pure function. For@pure-unless-parameter-passed, PHPStan reports the by-ref parameter aspureFunction.parameterByRef. For@pure-unless-callable-is-impure, the body check exempts the$cb()call, so neither the body check nor the callers notice an impure callback, and no existing error covers that case.Changes
ConflictingPurityTagsRuleresolves the docblock of a function or method withFileTypeMapperand reports each@pure-unless-*parameter when the same docblock has a purity tag:Function map() is marked as impure, which conflicts with @pure-unless-callable-is-impure for parameter $cb.(pureFunction.conflictingPurityTags/pureMethod.conflictingPurityTags). Aliases such as@psalm-pure,@impureand the@phpstan-pure-unless-*variants count.@phpstan-all-methods-pure/-impuredon't count. It covers interface, abstract, trait, enum and anonymous-class methods.@phpstan-purebut ignores@pure-unless-*, and closures, where neither tag applies. Like the other bleeding-edge rules, it doesn't validate stub files.@phpstan-pureand@phpstan-impure, the message says "marked as pure", sinceResolvedPhpDocBlock::isPure()prefers@phpstan-pure.pureFunction.parameterByReforpureFunction.redundantUnlessCallablefire for the same docblock, both errors appear.reportConflictingPurityTagsbleeding-edge toggle, next toPureFunctionRuleandPureMethodRule. The config lines touch the same spot as Check the purity declarations of methods without a body #6668, so whichever merges second needs a rebase.