Skip to content

Bump PHPStan rule level to 1#11151

Draft
westonruter wants to merge 15 commits intoWordPress:trunkfrom
westonruter:bump/phpstan-level-1
Draft

Bump PHPStan rule level to 1#11151
westonruter wants to merge 15 commits intoWordPress:trunkfrom
westonruter:bump/phpstan-level-1

Conversation

@westonruter
Copy link
Member

@westonruter westonruter commented Mar 4, 2026

By increasing the PHPStan rule level to 1, the following issues will begin to be detected for new code introduced to core:

possibly undefined variables, unknown magic methods and properties on classes with __call and __get

Here is the original tally of ignored errors in tests/phpstan/baseline.php categorized by their PHPStan identifier:

Identifier Description Error Count
empty.variable Using empty() on variables that always exist, are always falsy, or are not falsy 9
constant.notFound Usage of constants that are not found or defined in the analyzed scope 9
isset.variable Using isset() on variables that always exist, are not nullable, or are never defined 5
variable.undefined Accessing variables that are never defined or are possibly undefined 4
arguments.count Functions or methods invoked with more parameters than they actually require 4
constructor.unusedParameter Class constructors that have parameters that are never used 1
Total 32

And with the current fixes pushed to this branch, these are the remaining errors in the baseline:

Identifier Description Error Count
empty.variable Using empty() on variables that always exist, are always falsy, or are not falsy 9
isset.variable Using isset() on variables that always exist, are not nullable, or are never defined 4
arguments.count Functions or methods invoked with more parameters than they actually require 4
Total 17

This cherry-picks some commits from #11009.

See also #11037 which bumps to level 4.

Trac ticket: https://core.trac.wordpress.org/ticket/64680

Use of AI Tools

n/a


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.

@github-actions
Copy link

github-actions bot commented Mar 4, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props westonruter, apermo.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link

github-actions bot commented Mar 4, 2026

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

westonruter and others added 2 commits March 3, 2026 19:08
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@westonruter westonruter force-pushed the bump/phpstan-level-1 branch from e6bd045 to bf92684 Compare March 4, 2026 03:20
apermo and others added 7 commits March 3, 2026 19:24
PHPStan cannot verify that wp_die() always
terminates due to its conditional return type
and treatPhpDocTypesAsCertain being disabled.
Co-authored-by: Christoph Daum <christoph.daum@coding-pioneers.com>
Co-authored-by: Weston Ruter <westonruter@gmail.com>
@westonruter westonruter marked this pull request as draft March 4, 2026 03:38
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.

2 participants