#64680 closed task (blessed) (fixed)
Increase PHPStan rule level from zero
| Reported by: | westonruter | Owned by: | westonruter |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.1 |
| Component: | Build/Test Tools | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
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 (30)
This ticket was mentioned in PR #11037 on WordPress/wordpress-develop by @westonruter.
8 months 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.
7 months 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
#8
@
3 months ago
@westonruter, are there any other issues to address for the 7.1 release? If not, I'd like to punt this to 7.2.
#9
@
3 months ago
@wildworks this work is ongoing, yes. I'm eager to increase to at least level 1. I've been making various improvements to facilitate that. I may just go ahead and bump it with the baseline populated with existing errors so that we can catch new ones that arise.
#10
@
2 months ago
I'm still working on this. I see this important for validation that we didn't introduce major issues in 7.1, so please don't bump it from the milestone.
@westonruter commented on PR #11151:
2 months ago
#11
I just added 8ebe862 to re-introduce one of the fixes that I reverted in cce3ac023c2ff3dbb34f3bef853df95d49f412e0. This _should_ result in the PHPStan job failing with a helpful message, instructing the developer to regenerate the baselines.
@adamsilverstein commented on PR #11151:
2 months ago
#12
@westonruter commented on PR #11151:
2 months ago
#13
@westonruter commented on PR #11151:
2 months ago
#14
@westonruter commented on PR #11151:
2 months ago
#15
Oh, nevermind, it's right here in the Summary: https://github.com/WordPress/wordpress-develop/actions/runs/30981363599
@westonruter commented on PR #11151:
2 months ago
#16
This ticket was mentioned in PR #12852 on WordPress/wordpress-develop by @westonruter.
2 months ago
#18
Follow-up to https://github.com/WordPress/wordpress-develop/pull/11151 (r63019, e9e0be1)
Trac ticket: https://core.trac.wordpress.org/ticket/64680
## Use of AI Tools
n/a
@westonruter commented on PR #11151:
2 months ago
#19
Bump to rule level 2: https://github.com/WordPress/wordpress-develop/pull/12852
#21
@
2 months ago
Also committed r63021 to bump the rule level to 3 but I neglected to mention this ticket properly.
This ticket was mentioned in PR #12853 on WordPress/wordpress-develop by @westonruter.
2 months ago
#23
This rule level includes:
basic dead code checking - always false
instanceofand other type checks, deadelsebranches, unreachable code after return; etc.
Baselines are regenerated for errors at this level.
Follow-up to r61699, r63019, r63020, r63021, r63022.
Trac ticket: https://core.trac.wordpress.org/ticket/64680
$ composer phpstan:baselines
Analyzing with phpstan.neon.dist, existing baselines suppressed...
[OK] Baseline generated with 1391 errors.
tests/phpstan/baselines/arguments.count.neon: 6 entries, 9 errors
tests/phpstan/baselines/assign.propertyType.neon: 28 entries, 30 errors
tests/phpstan/baselines/binaryOp.invalid.neon: 3 entries, 4 errors
tests/phpstan/baselines/booleanAnd.alwaysFalse.neon: 2 entries, 2 errors
tests/phpstan/baselines/booleanAnd.alwaysTrue.neon: 1 entries, 2 errors
tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon: 5 entries, 5 errors
tests/phpstan/baselines/booleanAnd.rightAlwaysFalse.neon: 1 entries, 1 errors
tests/phpstan/baselines/booleanAnd.rightAlwaysTrue.neon: 9 entries, 16 errors
tests/phpstan/baselines/booleanNot.alwaysFalse.neon: 6 entries, 7 errors
tests/phpstan/baselines/booleanNot.alwaysTrue.neon: 8 entries, 8 errors
tests/phpstan/baselines/booleanOr.alwaysFalse.neon: 1 entries, 1 errors
tests/phpstan/baselines/booleanOr.alwaysTrue.neon: 2 entries, 2 errors
tests/phpstan/baselines/booleanOr.rightAlwaysTrue.neon: 1 entries, 1 errors
tests/phpstan/baselines/catch.neverThrown.neon: 1 entries, 1 errors
tests/phpstan/baselines/class.nameCase.neon: 1 entries, 1 errors
tests/phpstan/baselines/class.notFound.neon: 14 entries, 14 errors
tests/phpstan/baselines/deadCode.unreachable.neon: 57 entries, 91 errors
tests/phpstan/baselines/empty.offset.neon: 2 entries, 2 errors
tests/phpstan/baselines/empty.property.neon: 9 entries, 13 errors
tests/phpstan/baselines/empty.variable.neon: 9 entries, 9 errors
tests/phpstan/baselines/encapsedStringPart.nonString.neon: 1 entries, 1 errors
tests/phpstan/baselines/foreach.nonIterable.neon: 1 entries, 1 errors
tests/phpstan/baselines/function.alreadyNarrowedType.neon: 17 entries, 19 errors
tests/phpstan/baselines/function.impossibleType.neon: 4 entries, 6 errors
tests/phpstan/baselines/function.resultUnused.neon: 4 entries, 4 errors
tests/phpstan/baselines/greater.invalid.neon: 1 entries, 1 errors
tests/phpstan/baselines/greaterOrEqual.alwaysTrue.neon: 8 entries, 8 errors
tests/phpstan/baselines/identical.alwaysFalse.neon: 5 entries, 5 errors
tests/phpstan/baselines/identical.alwaysTrue.neon: 4 entries, 4 errors
tests/phpstan/baselines/if.alwaysFalse.neon: 7 entries, 8 errors
tests/phpstan/baselines/if.alwaysTrue.neon: 7 entries, 9 errors
tests/phpstan/baselines/instanceof.alwaysTrue.neon: 1 entries, 1 errors
tests/phpstan/baselines/isset.offset.neon: 4 entries, 4 errors
tests/phpstan/baselines/isset.property.neon: 40 entries, 44 errors
tests/phpstan/baselines/isset.variable.neon: 6 entries, 6 errors
tests/phpstan/baselines/method.childParameterType.neon: 7 entries, 7 errors
tests/phpstan/baselines/method.nonObject.neon: 7 entries, 7 errors
tests/phpstan/baselines/method.notFound.neon: 5 entries, 5 errors
tests/phpstan/baselines/method.unused.neon: 5 entries, 5 errors
tests/phpstan/baselines/notIdentical.alwaysTrue.neon: 11 entries, 13 errors
tests/phpstan/baselines/nullCoalesce.offset.neon: 1 entries, 1 errors
tests/phpstan/baselines/nullCoalesce.property.neon: 7 entries, 7 errors
tests/phpstan/baselines/offsetAccess.nonOffsetAccessible.neon: 3 entries, 6 errors
tests/phpstan/baselines/offsetAccess.notFound.neon: 4 entries, 6 errors
tests/phpstan/baselines/offsetAssign.valueType.neon: 1 entries, 2 errors
tests/phpstan/baselines/parameter.defaultValue.neon: 17 entries, 17 errors
tests/phpstan/baselines/parameter.notFound.neon: 3 entries, 3 errors
tests/phpstan/baselines/parameter.phpDocType.neon: 1 entries, 1 errors
tests/phpstan/baselines/parameter.unresolvableType.neon: 1 entries, 1 errors
tests/phpstan/baselines/parameterByRef.type.neon: 6 entries, 8 errors
tests/phpstan/baselines/parameterByRef.unusedType.neon: 2 entries, 2 errors
tests/phpstan/baselines/property.defaultValue.neon: 18 entries, 18 errors
tests/phpstan/baselines/property.nonObject.neon: 47 entries, 75 errors
tests/phpstan/baselines/property.notFound.neon: 62 entries, 113 errors
tests/phpstan/baselines/property.onlyWritten.neon: 1 entries, 1 errors
tests/phpstan/baselines/property.phpDocType.neon: 5 entries, 5 errors
tests/phpstan/baselines/property.private.neon: 8 entries, 29 errors
tests/phpstan/baselines/property.protected.neon: 8 entries, 11 errors
tests/phpstan/baselines/property.unusedType.neon: 1 entries, 1 errors
tests/phpstan/baselines/return.empty.neon: 2 entries, 2 errors
tests/phpstan/baselines/return.missing.neon: 41 entries, 44 errors
tests/phpstan/baselines/return.type.neon: 29 entries, 32 errors
tests/phpstan/baselines/return.unusedType.neon: 16 entries, 16 errors
tests/phpstan/baselines/smallerOrEqual.alwaysTrue.neon: 1 entries, 1 errors
tests/phpstan/baselines/staticClassAccess.privateMethod.neon: 34 entries, 55 errors
tests/phpstan/baselines/ternary.alwaysFalse.neon: 1 entries, 2 errors
tests/phpstan/baselines/ternary.alwaysTrue.neon: 2 entries, 2 errors
tests/phpstan/baselines/varTag.noVariable.neon: 8 entries, 17 errors
tests/phpstan/baselines/variable.undefined.neon: 195 entries, 479 errors
tests/phpstan/baselines/while.alwaysFalse.neon: 1 entries, 1 errors
tests/phpstan/baselines/while.alwaysTrue.neon: 56 entries, 56 errors
phpstan.neon.dist: `includes` updated.
## Use of AI Tools
n/a
@westonruter commented on PR #12853:
2 months ago
#24
There are quite a few error identifiers introduced at this level.
The next level up is level 5, which is much smaller, only introducing 3:
M phpstan.neon.dist A tests/phpstan/baselines/argument.type.neon A tests/phpstan/baselines/argument.unresolvableType.neon A tests/phpstan/baselines/arrayValues.list.neon
#25
@
2 months ago
Note: I think it makes sense to stop the rule level bumping at level 5 for the foreseeable future. Level 6 is "report missing typehints" which would be extensive across core. We'd likely need to add quite a few ignoreErrors to phpstan.neon.dist for that, as we surely would not be looking to retroactively add type hints everywhere.
This ticket was mentioned in PR #12855 on WordPress/wordpress-develop by @westonruter.
2 months ago
#27
This rule level includes:
checking types of arguments passed to methods and functions
Follow-up to r61699, r63019, r63020, r63021, r63022, r63023.
Trac ticket: https://core.trac.wordpress.org/ticket/64680
$ composer phpstan:baselines
Analyzing with phpstan.neon.dist, existing baselines suppressed...
[OK] Baseline generated with 1901 errors.
tests/phpstan/baselines/argument.type.neon: 373 entries, 507 errors
tests/phpstan/baselines/argument.unresolvableType.neon: 1 entries, 2 errors
tests/phpstan/baselines/arguments.count.neon: 6 entries, 9 errors
tests/phpstan/baselines/arrayValues.list.neon: 1 entries, 1 errors
tests/phpstan/baselines/assign.propertyType.neon: 28 entries, 30 errors
tests/phpstan/baselines/binaryOp.invalid.neon: 3 entries, 4 errors
tests/phpstan/baselines/booleanAnd.alwaysFalse.neon: 2 entries, 2 errors
tests/phpstan/baselines/booleanAnd.alwaysTrue.neon: 1 entries, 2 errors
tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon: 5 entries, 5 errors
tests/phpstan/baselines/booleanAnd.rightAlwaysFalse.neon: 1 entries, 1 errors
tests/phpstan/baselines/booleanAnd.rightAlwaysTrue.neon: 9 entries, 16 errors
tests/phpstan/baselines/booleanNot.alwaysFalse.neon: 6 entries, 7 errors
tests/phpstan/baselines/booleanNot.alwaysTrue.neon: 8 entries, 8 errors
tests/phpstan/baselines/booleanOr.alwaysFalse.neon: 1 entries, 1 errors
tests/phpstan/baselines/booleanOr.alwaysTrue.neon: 2 entries, 2 errors
tests/phpstan/baselines/booleanOr.rightAlwaysTrue.neon: 1 entries, 1 errors
tests/phpstan/baselines/catch.neverThrown.neon: 1 entries, 1 errors
tests/phpstan/baselines/class.nameCase.neon: 1 entries, 1 errors
tests/phpstan/baselines/class.notFound.neon: 14 entries, 14 errors
tests/phpstan/baselines/deadCode.unreachable.neon: 57 entries, 91 errors
tests/phpstan/baselines/empty.offset.neon: 2 entries, 2 errors
tests/phpstan/baselines/empty.property.neon: 9 entries, 13 errors
tests/phpstan/baselines/empty.variable.neon: 9 entries, 9 errors
tests/phpstan/baselines/encapsedStringPart.nonString.neon: 1 entries, 1 errors
tests/phpstan/baselines/foreach.nonIterable.neon: 1 entries, 1 errors
tests/phpstan/baselines/function.alreadyNarrowedType.neon: 17 entries, 19 errors
tests/phpstan/baselines/function.impossibleType.neon: 4 entries, 6 errors
tests/phpstan/baselines/function.resultUnused.neon: 4 entries, 4 errors
tests/phpstan/baselines/greater.invalid.neon: 1 entries, 1 errors
tests/phpstan/baselines/greaterOrEqual.alwaysTrue.neon: 8 entries, 8 errors
tests/phpstan/baselines/identical.alwaysFalse.neon: 5 entries, 5 errors
tests/phpstan/baselines/identical.alwaysTrue.neon: 4 entries, 4 errors
tests/phpstan/baselines/if.alwaysFalse.neon: 7 entries, 8 errors
tests/phpstan/baselines/if.alwaysTrue.neon: 7 entries, 9 errors
tests/phpstan/baselines/instanceof.alwaysTrue.neon: 1 entries, 1 errors
tests/phpstan/baselines/isset.offset.neon: 4 entries, 4 errors
tests/phpstan/baselines/isset.property.neon: 40 entries, 44 errors
tests/phpstan/baselines/isset.variable.neon: 6 entries, 6 errors
tests/phpstan/baselines/method.childParameterType.neon: 7 entries, 7 errors
tests/phpstan/baselines/method.nonObject.neon: 7 entries, 7 errors
tests/phpstan/baselines/method.notFound.neon: 5 entries, 5 errors
tests/phpstan/baselines/method.unused.neon: 5 entries, 5 errors
tests/phpstan/baselines/notIdentical.alwaysTrue.neon: 11 entries, 13 errors
tests/phpstan/baselines/nullCoalesce.offset.neon: 1 entries, 1 errors
tests/phpstan/baselines/nullCoalesce.property.neon: 7 entries, 7 errors
tests/phpstan/baselines/offsetAccess.nonOffsetAccessible.neon: 3 entries, 6 errors
tests/phpstan/baselines/offsetAccess.notFound.neon: 4 entries, 6 errors
tests/phpstan/baselines/offsetAssign.valueType.neon: 1 entries, 2 errors
tests/phpstan/baselines/parameter.defaultValue.neon: 17 entries, 17 errors
tests/phpstan/baselines/parameter.notFound.neon: 3 entries, 3 errors
tests/phpstan/baselines/parameter.phpDocType.neon: 1 entries, 1 errors
tests/phpstan/baselines/parameter.unresolvableType.neon: 1 entries, 1 errors
tests/phpstan/baselines/parameterByRef.type.neon: 6 entries, 8 errors
tests/phpstan/baselines/parameterByRef.unusedType.neon: 2 entries, 2 errors
tests/phpstan/baselines/property.defaultValue.neon: 18 entries, 18 errors
tests/phpstan/baselines/property.nonObject.neon: 47 entries, 75 errors
tests/phpstan/baselines/property.notFound.neon: 62 entries, 113 errors
tests/phpstan/baselines/property.onlyWritten.neon: 1 entries, 1 errors
tests/phpstan/baselines/property.phpDocType.neon: 5 entries, 5 errors
tests/phpstan/baselines/property.private.neon: 8 entries, 29 errors
tests/phpstan/baselines/property.protected.neon: 8 entries, 11 errors
tests/phpstan/baselines/property.unusedType.neon: 1 entries, 1 errors
tests/phpstan/baselines/return.empty.neon: 2 entries, 2 errors
tests/phpstan/baselines/return.missing.neon: 41 entries, 44 errors
tests/phpstan/baselines/return.type.neon: 29 entries, 32 errors
tests/phpstan/baselines/return.unusedType.neon: 16 entries, 16 errors
tests/phpstan/baselines/smallerOrEqual.alwaysTrue.neon: 1 entries, 1 errors
tests/phpstan/baselines/staticClassAccess.privateMethod.neon: 34 entries, 55 errors
tests/phpstan/baselines/ternary.alwaysFalse.neon: 1 entries, 2 errors
tests/phpstan/baselines/ternary.alwaysTrue.neon: 2 entries, 2 errors
tests/phpstan/baselines/varTag.noVariable.neon: 8 entries, 17 errors
tests/phpstan/baselines/variable.undefined.neon: 195 entries, 479 errors
tests/phpstan/baselines/while.alwaysFalse.neon: 1 entries, 1 errors
tests/phpstan/baselines/while.alwaysTrue.neon: 56 entries, 56 errors
## Use of AI Tools
n/a
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
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.