Make WordPress Core

Opened 8 months ago

Closed 2 months ago

Last modified 2 months ago

#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)

#1 @westonruter
8 months ago

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 trunk to 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.

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:

  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.

#3 @westonruter
8 months ago

See above for ​PR which bumps the rule level to 4.

#4 @westonruter
8 months ago

  • Owner set to westonruter
  • Status new → accepted

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 __call and __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

#6 @westonruter
7 months ago

In 62000:

Twenty Seventeen: Restore $post_id parameter to twentyseventeen_edit_link() which is being passed in some templates.

This addresses arguments.count errors identified by PHPStan at rule level 1.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/11242

Follow-up to WordPress/twentyseventeen commits: ​1afb73c, ​7dd3025, ​6948288.

Props sabernhardt, westonruter.
See #64680.
Fixes #64825.

#7 @westonruter
7 months ago

  • Milestone 7.0 → 7.1

Punting since we're at RC1.

#8 @wildworks
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 @westonruter
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 @westonruter
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

I just added ​8ebe862 to re-introduce one of the fixes that I reverted in ​cce3ac0. This _should_ result in the PHPStan job failing with a helpful message, instructing the developer to regenerate the baselines.

looks like that worked:

https://github.com/user-attachments/assets/c8485350-e0f4-4f07-b618-dcd92020702e

​@westonruter commented on ​PR #11151:


2 months ago
#13

Here's the message that shows up with the failed job:

https://github.com/user-attachments/assets/decc1ddd-d9ad-4abe-b96a-e941b99c94e7

​@westonruter commented on ​PR #11151:


2 months ago
#14

Also shown at the top:

https://github.com/user-attachments/assets/78dc5905-3e6e-4ff9-9d5b-97e55f01b1b1

But I'm not seeing the step summary as expected:

https://github.com/user-attachments/assets/2e5d4818-7494-4bbb-8d45-f45a8197ef06

​@westonruter commented on ​PR #11151:


2 months ago
#16

Alright, looking good:

https://github.com/user-attachments/assets/ac31990d-04d5-4d82-abb0-c1fe1512e8b7

https://github.com/user-attachments/assets/1fa80f12-c23b-4260-bb52-57a2ac1e29e2

#17 @westonruter
2 months ago

  • Resolution → fixed
  • Status accepted → closed

In 63019:

Build/Test Tools: Raise the PHPStan rule level to 1.

Level 1 adds detection of possibly undefined variables, and of unknown magic methods and properties on classes with __call and __get. The 494 errors this surfaces in existing code are recorded in baselines rather than being fixed here, so that new code is held to level 1 straight away while the existing reports are worked through separately. No files under src are changed.

The tests/phpstan/baseline.php file is replaced by one baseline per error identifier under tests/phpstan/baselines, so that the remaining work on each kind of error is visible as a single file that should shrink to nothing and then be deleted. Every entry is scoped to the file which the error occurs in and carries an exact occurrence count, so that a new occurrence of an already baselined error is reported rather than absorbed. The consequence is that fixing a baselined error means regenerating its baseline in the same change, because the count no longer matches.

PHPStan's own --generate-baseline captures every error a run reports, with no way to restrict it to one identifier, so tests/phpstan/generate-baselines.php is added to write the files instead, exposed as composer phpstan:baselines and as npm run typecheck:php:baselines. A run also deletes any baseline whose identifier no longer reports anything, and rewrites the list of baselines in phpstan.neon.dist. The ignoreErrors in that file now has a comment explaining how it is distinct from a baseline: an entry there is a decision that the code is right as written, whereas a baseline entry is work still to be done. The constants that add_theme_support() defines are declared in the configuration so that the errors around them are resolved rather than recorded, and tests/phpstan/README.md is updated throughout.

Three problems in the static analysis GHA workflow are fixed as well. Fixing a baselined error makes PHPStan report an unmatched ignore, which surfaced only as an annotation reading like a complaint about a correct fix; the job now detects any ignore.* report and fails with an explanation of what to run. An analysis that did not finish passed as a green run, because the status of the pipeline was that of cs2pr rather than of PHPStan; that status is now recovered and a run that did not finish fails. The path filter deciding whether the workflow runs named only the old baseline file, so a pull request that merely regenerated the baselines would not have run the analysis that checks them.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/11151.
Follow-up to r61699.

Props westonruter, sabernhardt, apermo, johnjamesjacoby, adamsilverstein, justlevine.
See #61175.
Fixes #64680.

#20 @westonruter
2 months ago

In 63020:

Build/Test Tools: Raise the PHPStan rule level to 2.

This rule level includes:

unknown methods checked on all expressions (not just $this), validating PHPDocs

Baselines are regenerated for errors at this level.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/12852.
Follow-up to r61699, r63019.

Props westonruter, apermo.
See #64680.

#21 @westonruter
2 months ago

Also committed r63021 to bump the rule level to 3 but I neglected to mention this ticket properly.

#22 @westonruter
2 months ago

In 63022:

Build/Test Tools: Add missing baselines from PHPStan level 3 bump.

Follow-up to r63021.

See #64680.

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 instanceof and other type checks, dead else branches, 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 @westonruter
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.

#26 @westonruter
2 months ago

In 63023:

Build/Test Tools: Raise the PHPStan rule level to 4.

This rule level includes:

basic dead code checking - always false instanceof and other type checks, dead else branches, unreachable code after return; etc.

Baselines are regenerated for errors at this level.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/12853.
Follow-up to r61699, r63019, r63020, r63021, r63022.

Props westonruter, apermo.
See #64680.

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

#28 @westonruter
2 months ago

In 63024:

Build/Test Tools: Raise the PHPStan rule level to 5.

This rule level includes:

checking types of arguments passed to methods and functions

Baselines are regenerated for errors at this level.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/12855.
Follow-up to r61699, r63019, r63020, r63021, r63022, r63023.

Props westonruter, apermo.
See #64680.

​@westonruter commented on ​PR #11037:


2 months ago
#29

This PR was auto-closed with the fixing of the ticket, but the changes in this PR were not specifically committed.

The PHPStan was bumped to rule level 4 in r63023 and then rule level 5 in r63024.

#30 @westonruter
2 months ago

In 63294:

Build/Test Tools: Suppress every PHPStan baseline when regenerating.

The strip_baseline_includes() function in generate-baselines.php dropped an includes entry only when it resolved inside the output directory. With the default output directory, that test covers the managed region exactly, so nothing appeared amiss. When --output-dir was used to point the output elsewhere, however, every baseline already in force stayed active for the analysis, which then reported only the errors those baselines did not already cover: a differential baseline where a complete one was requested.

Strip the region between the # phpstan:baselines markers whatever it points at, since that region is generated and lists every baseline in force. The output directory test is kept as well, so a baseline listed by hand outside the markers is still suppressed when it is about to be rewritten.

Found while generating a baseline from the 7.0.0 source tree to identify which errors have been introduced since: with the managed region left in place, PHPStan refused to start at all, as two of the entries named files which do not exist in 7.0.0.

Follow-up to r63019.

See #64680, #65817.

Note: See TracTickets for help on using tickets.