Repository navigation
Docs: Add PHPStan type assertions - #13896
Closed
swissspidy wants to merge 8 commits into
Closed
swissspidy wants to merge 8 commits into
swissspidy wants to merge 8 commits into
Conversation
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.
✅ Committed in r64795 (9b095dd).
Split out of #13530, as proposed in this comment (subset 9).
@phpstan-assert-if-trueis added towp_is_stream(),wp_is_uuid(),shortcode_exists(),has_shortcode()andtaxonomy_exists().path_is_absolute()'s existing assertion is changed to the equality form,=non-falsy-string.Changes from #13530
These follow the review analysis:
wp_is_uuid()asserts=lowercase-string&non-falsy-stringwithout theTUuid of stringtemplate, which rejected themixedits callers pass.Changes after review
@phpstan-impureannotations are removed for now. Much of WordPress depends on globals and the database, so nearly every function could be marked impure. Core should first agree on which functions to mark, for example only deliberately random ones such aswp_rand()and ones especially likely to change between calls such asget_transient(), as php-stubs does.@phpstan-pureannotations are removed as well. With the defaultrememberPossiblyImpureFunctionValues: true, PHPStan already remembers return values, so@phpstan-purechanges nothing (see Remembering and forgetting returned values).path_is_absolute()gained@phpstan-assert-if-true non-falsy-string $pathin trunk (r64235), so this PR no longer adds it. That form is not an equality assertion, so PHPStan also applied its negation when the function returnsfalse. A relative path likefoo/baris still a non-falsy string, yet an argument already typednon-falsy-stringwas narrowed toneverin the false branch, making it look unreachable. The=prefix narrows only the true branch, as with the other assertions here.Effect on the analysis
composer run phpstanpasses with no baseline changes.Trac ticket: https://core.trac.wordpress.org/ticket/65817
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Splitting #13530 by tag kind, applying the corrections from the review analysis on #13530 and from review on this PR, checking the result with
composer run phpstanand drafting the commit messages and this description. Reviewed by me.This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.
🤖 Generated with Claude Code
https://claude.ai/code/session_01T3XYNUvB9sQNDXA14uJQeH