Skip to content

Bump PHPStan rule level to 4#11037

Open
westonruter wants to merge 133 commits intoWordPress:trunkfrom
westonruter:bump/phpstan-level-4
Open

Bump PHPStan rule level to 4#11037
westonruter wants to merge 133 commits intoWordPress:trunkfrom
westonruter:bump/phpstan-level-4

Conversation

@westonruter
Copy link
Member

@westonruter westonruter commented Feb 25, 2026

This PR is based off of #7619, see additional commits: justlevine/wordpress-develop@feat/phpstan...westonruter:wordpress-develop:bump/phpstan-level-4

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

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

  1. possibly undefined variables, unknown magic methods and properties on classes with __call and __get
  2. unknown methods checked on all expressions (not just $this), validating PHPDocs
  3. return types, types assigned to properties
  4. basic dead code checking - always false instanceof and other type checks, dead else branches, unreachable code after return; etc.

Existing errors for these levels are ignored by a baseline which has been updated to include 641 errors:

Count PHPStan Identifier
56 while.alwaysTrue
55 deadCode.unreachable
53 property.notFound
52 property.nonObject
36 isset.property
34 return.type
29 staticClassAccess.privateMethod
23 assign.propertyType
19 property.defaultValue
16 class.notFound
14 method.unused
13 method.nonObject
13 function.alreadyNarrowedType
12 booleanAnd.rightAlwaysTrue
10 return.unusedType
10 notIdentical.alwaysTrue
9 empty.variable
9 empty.property
9 arguments.count
8 varTag.noVariable
8 greaterOrEqual.alwaysTrue
8 constant.notFound
8 booleanNot.alwaysTrue
7 property.private
7 parameterByRef.type
7 method.childParameterType
6 phpDoc.parseError
6 if.alwaysFalse
5 property.phpDocType
5 parameter.defaultValue
5 nullCoalesce.property
5 method.notFound
5 isset.variable
5 isset.offset
5 if.alwaysTrue
4 variable.undefined
4 parameter.notFound
4 identical.alwaysFalse
4 booleanAnd.leftAlwaysTrue
3 return.missing
3 property.protected
3 offsetAccess.notFound
3 booleanNot.alwaysFalse
3 booleanAnd.alwaysFalse
3 binaryOp.invalid
2 ternary.alwaysFalse
2 return.empty
2 property.unusedType
2 parameterByRef.unusedType
2 offsetAccess.nonOffsetAccessible
2 nullCoalesce.offset
2 identical.alwaysTrue
2 function.impossibleType
2 empty.offset
2 booleanOr.alwaysTrue
1 while.alwaysFalse
1 ternary.alwaysTrue
1 smallerOrEqual.alwaysTrue
1 property.onlyWritten
1 parameter.unresolvableType
1 parameter.phpDocType
1 offsetAssign.valueType
1 instanceof.alwaysTrue
1 foreach.nonIterable
1 encapsedStringPart.nonString
1 constructor.unusedParameter
1 booleanOr.rightAlwaysTrue
1 booleanOr.alwaysFalse
1 booleanAnd.rightAlwaysFalse
1 booleanAnd.alwaysTrue

Use of AI Tools

Summarizing the ignored errors in the baseline.


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.

This makes it easier to use this branch for cherrypicking/remediation, even if the eventual version of _this_ pr will need to be downgraded back down to 1.x
westonruter and others added 25 commits February 18, 2026 10:19
Co-authored-by: Jonathan Desrosiers <359867+desrosj@users.noreply.github.com>
Co-authored-by: John Blackbourn <johnbillion@git.wordpress.org>
Co-authored-by: John Blackbourn <john@johnblackbourn.com>
Co-authored-by: John Blackbourn <john@johnblackbourn.com>
The generate-baselines.sh script now automatically reads the maximum level from phpstan.neon or phpstan.neon.dist instead of using a hardcoded value.

Additionally, the script was updated to use indexed arrays for compatibility with Bash 3.2 (macOS default), and the README was updated to reflect these changes and fix minor typos.

Co-authored-by: gemini-cli <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@github-actions
Copy link

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 justlevine, johnbillion, westonruter.

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

@github-actions
Copy link

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 westonruter requested a review from desrosj February 25, 2026 06:59
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.

3 participants