Repository navigation
Report functions that can be marked @phpstan-pure, with a fix - #6933
Open
SanderMuller wants to merge 1 commit into
Open
SanderMuller wants to merge 1 commit into
SanderMuller wants to merge 1 commit into
Conversation
With checkMissingPurePhpDocTag enabled, the pure function and method rules report a function or method without a purity tag that returns a value and has no impure points, no explicit throw points, no asserts, no by-reference parameters and no by-reference return. Methods are reported only when they cannot be overridden. The fix adds @phpstan-pure to the PHPDoc. Callers of a function marked this way are reported in the next fix round. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
This adds an opt-in parameter,
checkMissingPurePhpDocTag. When it is enabled,PureFunctionRuleandPureMethodRulereport a function or method that has no purity tag but can be marked@phpstan-pure. The error has a fix that adds the tag, so--fixcan mark a codebase.A function is reported when all of these are true:
@phpstan-pureor@phpstan-impuretag, and no pure-unless parameters.voidreturn, a generator and a by-reference return are skipped.@throwsother thanvoid.A method is reported only when it cannot be overridden: it is private, final, or in a final class. Trait methods are skipped.
Each fix round marks one call level. A caller of a function that was just marked gets its report in the next round. So
--fixneeds a few rounds on a large codebase.I ran
--fixon PHPStan's ownsrc. It added 3663 tags in 1169 files over 5 rounds. After that, a normal self-analysis gave no purity errors. The only new errors came fromArenaCache::attach(): onestaticMethod.resultUnusedand oneignore.unmatched. I did not commit those tags.The parameter needs a line in the config reference on phpstan.org. I can open that PR after this one.
🤖 Generated with Claude Code