Skip to content

Docs: Add PHPStan type assertions - #13896

Closed
swissspidy wants to merge 8 commits into
WordPress:trunkfrom
swissspidy:fix/phpstan-assertions-purity
Closed

swissspidy wants to merge 8 commits into
WordPress:trunkfrom
swissspidy:fix/phpstan-assertions-purity

Conversation

@swissspidy

@swissspidy swissspidy commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

✅ Committed in r64795 (9b095dd).


Split out of #13530, as proposed in this comment (subset 9).

  • @phpstan-assert-if-true is added to wp_is_stream(), wp_is_uuid(), shortcode_exists(), has_shortcode() and taxonomy_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-string without the TUuid of string template, which rejected the mixed its callers pass.

Changes after review

  • The @phpstan-impure annotations 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 as wp_rand() and ones especially likely to change between calls such as get_transient(), as php-stubs does.
  • The @phpstan-pure annotations are removed as well. With the default rememberPossiblyImpureFunctionValues: true, PHPStan already remembers return values, so @phpstan-pure changes nothing (see Remembering and forgetting returned values).
  • path_is_absolute() gained @phpstan-assert-if-true non-falsy-string $path in 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 returns false. A relative path like foo/bar is still a non-falsy string, yet an argument already typed non-falsy-string was narrowed to never in 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 phpstan passes 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 phpstan and 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

Loading
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

Successfully merging this pull request may close these issues.

4 participants