Opened 7 weeks ago
Last modified 3 weeks ago
#64680 accepted task (blessed)
Increase PHPStan rule level from zero
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 7.1 | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Build/Test Tools | Keywords: | has-patch has-unit-tests |
| Focuses: | Cc: |
Description
PHPStan is now integrated into the core development workflow as of #61175. The initial commit (r61699), however, set the rule level to 0 (zero).
That ticket initially had a PR which set the rule level to 6, with initial baselines to ignore existing errors but to catch new ones as they are introduced.
We can now move forward with that.
Change History (7)
This ticket was mentioned in PR #11037 on WordPress/wordpress-develop by @westonruter.
7 weeks ago
#2
- Keywords has-unit-tests added
This PR is based off of https://github.com/WordPress/wordpress-develop/pull/7619, see additional commits: https://github.com/justlevine/wordpress-develop/compare/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:
- possibly undefined variables, unknown magic methods and properties on classes with
__calland__get - unknown methods checked on all expressions (not just
$this), validating PHPDocs - return types, types assigned to properties
- basic dead code checking - always false
instanceofand other type checks, deadelsebranches, 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 ticket was mentioned in PR #11151 on WordPress/wordpress-develop by @westonruter.
6 weeks ago
#5
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
__calland__get
Here is the 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 |
See also https://github.com/WordPress/wordpress-develop/pull/11037 which bumps to level 4.
Trac ticket: https://core.trac.wordpress.org/ticket/64680
## Use of AI Tools
n/a
I resolved the merge conflicts in the PR which set the rule level to 6, by merging the commits from the sub-PR back into it and then merging in
trunkto assist with Git's conflict resolution. So there are a ton of commits on that PR, but now the actual number of files changes is quite small.