Skip to content

Commit 79d902a

Browse files
committed
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 #12853. Follow-up to r61699, r63019, r63020, r63021, r63022. Props westonruter, apermo. See #64680. git-svn-id: https://develop.svn.wordpress.org/trunk@63023 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 194916f commit 79d902a

39 files changed

Lines changed: 2354 additions & 1 deletion

phpstan.neon.dist

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,45 @@ includes:
2525
- tests/phpstan/baselines/arguments.count.neon
2626
- tests/phpstan/baselines/assign.propertyType.neon
2727
- tests/phpstan/baselines/binaryOp.invalid.neon
28+
- tests/phpstan/baselines/booleanAnd.alwaysFalse.neon
29+
- tests/phpstan/baselines/booleanAnd.alwaysTrue.neon
30+
- tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon
31+
- tests/phpstan/baselines/booleanAnd.rightAlwaysFalse.neon
32+
- tests/phpstan/baselines/booleanAnd.rightAlwaysTrue.neon
33+
- tests/phpstan/baselines/booleanNot.alwaysFalse.neon
34+
- tests/phpstan/baselines/booleanNot.alwaysTrue.neon
35+
- tests/phpstan/baselines/booleanOr.alwaysFalse.neon
36+
- tests/phpstan/baselines/booleanOr.alwaysTrue.neon
37+
- tests/phpstan/baselines/booleanOr.rightAlwaysTrue.neon
38+
- tests/phpstan/baselines/catch.neverThrown.neon
2839
- tests/phpstan/baselines/class.nameCase.neon
2940
- tests/phpstan/baselines/class.notFound.neon
41+
- tests/phpstan/baselines/deadCode.unreachable.neon
42+
- tests/phpstan/baselines/empty.offset.neon
43+
- tests/phpstan/baselines/empty.property.neon
3044
- tests/phpstan/baselines/empty.variable.neon
3145
- tests/phpstan/baselines/encapsedStringPart.nonString.neon
3246
- tests/phpstan/baselines/foreach.nonIterable.neon
47+
- tests/phpstan/baselines/function.alreadyNarrowedType.neon
48+
- tests/phpstan/baselines/function.impossibleType.neon
49+
- tests/phpstan/baselines/function.resultUnused.neon
3350
- tests/phpstan/baselines/greater.invalid.neon
51+
- tests/phpstan/baselines/greaterOrEqual.alwaysTrue.neon
52+
- tests/phpstan/baselines/identical.alwaysFalse.neon
53+
- tests/phpstan/baselines/identical.alwaysTrue.neon
54+
- tests/phpstan/baselines/if.alwaysFalse.neon
55+
- tests/phpstan/baselines/if.alwaysTrue.neon
56+
- tests/phpstan/baselines/instanceof.alwaysTrue.neon
57+
- tests/phpstan/baselines/isset.offset.neon
58+
- tests/phpstan/baselines/isset.property.neon
3459
- tests/phpstan/baselines/isset.variable.neon
3560
- tests/phpstan/baselines/method.childParameterType.neon
3661
- tests/phpstan/baselines/method.nonObject.neon
3762
- tests/phpstan/baselines/method.notFound.neon
63+
- tests/phpstan/baselines/method.unused.neon
64+
- tests/phpstan/baselines/notIdentical.alwaysTrue.neon
65+
- tests/phpstan/baselines/nullCoalesce.offset.neon
66+
- tests/phpstan/baselines/nullCoalesce.property.neon
3867
- tests/phpstan/baselines/offsetAccess.nonOffsetAccessible.neon
3968
- tests/phpstan/baselines/offsetAccess.notFound.neon
4069
- tests/phpstan/baselines/offsetAssign.valueType.neon
@@ -43,23 +72,32 @@ includes:
4372
- tests/phpstan/baselines/parameter.phpDocType.neon
4473
- tests/phpstan/baselines/parameter.unresolvableType.neon
4574
- tests/phpstan/baselines/parameterByRef.type.neon
75+
- tests/phpstan/baselines/parameterByRef.unusedType.neon
4676
- tests/phpstan/baselines/property.defaultValue.neon
4777
- tests/phpstan/baselines/property.nonObject.neon
4878
- tests/phpstan/baselines/property.notFound.neon
79+
- tests/phpstan/baselines/property.onlyWritten.neon
4980
- tests/phpstan/baselines/property.phpDocType.neon
5081
- tests/phpstan/baselines/property.private.neon
5182
- tests/phpstan/baselines/property.protected.neon
83+
- tests/phpstan/baselines/property.unusedType.neon
5284
- tests/phpstan/baselines/return.empty.neon
5385
- tests/phpstan/baselines/return.missing.neon
5486
- tests/phpstan/baselines/return.type.neon
87+
- tests/phpstan/baselines/return.unusedType.neon
88+
- tests/phpstan/baselines/smallerOrEqual.alwaysTrue.neon
5589
- tests/phpstan/baselines/staticClassAccess.privateMethod.neon
90+
- tests/phpstan/baselines/ternary.alwaysFalse.neon
91+
- tests/phpstan/baselines/ternary.alwaysTrue.neon
5692
- tests/phpstan/baselines/varTag.noVariable.neon
5793
- tests/phpstan/baselines/variable.undefined.neon
94+
- tests/phpstan/baselines/while.alwaysFalse.neon
95+
- tests/phpstan/baselines/while.alwaysTrue.neon
5896
# phpstan:baselines end
5997

6098
parameters:
6199
# https://phpstan.org/user-guide/rule-levels
62-
level: 3
100+
level: 4
63101
reportUnmatchedIgnoredErrors: true
64102

65103
# The following ignored errors are not intended to be fixed, as distinct from the baselines
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# PHPStan baseline for the `booleanAnd.alwaysFalse` errors in WordPress core.
2+
#
3+
# https://phpstan.org/error-identifiers/booleanAnd.alwaysFalse
4+
#
5+
# Each entry is scoped to a single file and carries an exact occurrence count,
6+
# so that a new instance is reported as a new error rather than being absorbed
7+
# silently. Fixing an occurrence therefore means decrementing or removing its
8+
# entry here as part of the same change.
9+
#
10+
# The goal is to empty this file and delete it, along with the `includes` entry
11+
# for it in phpstan.neon.dist.
12+
#
13+
# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with
14+
#
15+
# composer phpstan:baselines -- --identifier=booleanAnd.alwaysFalse
16+
#
17+
# which reruns the analysis with this file suppressed so the errors surface again.
18+
19+
parameters:
20+
ignoreErrors:
21+
-
22+
message: '#^Result of && is always false\.$#'
23+
identifier: booleanAnd.alwaysFalse
24+
count: 1
25+
path: ../../../src/wp-admin/themes.php
26+
-
27+
message: '#^Result of && is always false\.$#'
28+
identifier: booleanAnd.alwaysFalse
29+
count: 1
30+
path: ../../../src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# PHPStan baseline for the `booleanAnd.alwaysTrue` errors in WordPress core.
2+
#
3+
# https://phpstan.org/error-identifiers/booleanAnd.alwaysTrue
4+
#
5+
# Each entry is scoped to a single file and carries an exact occurrence count,
6+
# so that a new instance is reported as a new error rather than being absorbed
7+
# silently. Fixing an occurrence therefore means decrementing or removing its
8+
# entry here as part of the same change.
9+
#
10+
# The goal is to empty this file and delete it, along with the `includes` entry
11+
# for it in phpstan.neon.dist.
12+
#
13+
# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with
14+
#
15+
# composer phpstan:baselines -- --identifier=booleanAnd.alwaysTrue
16+
#
17+
# which reruns the analysis with this file suppressed so the errors surface again.
18+
19+
parameters:
20+
ignoreErrors:
21+
-
22+
message: '#^Result of && is always true\.$#'
23+
identifier: booleanAnd.alwaysTrue
24+
count: 2
25+
path: ../../../src/wp-includes/html-api/class-wp-html-tag-processor.php
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# PHPStan baseline for the `booleanAnd.leftAlwaysTrue` errors in WordPress core.
2+
#
3+
# https://phpstan.org/error-identifiers/booleanAnd.leftAlwaysTrue
4+
#
5+
# Each entry is scoped to a single file and carries an exact occurrence count,
6+
# so that a new instance is reported as a new error rather than being absorbed
7+
# silently. Fixing an occurrence therefore means decrementing or removing its
8+
# entry here as part of the same change.
9+
#
10+
# The goal is to empty this file and delete it, along with the `includes` entry
11+
# for it in phpstan.neon.dist.
12+
#
13+
# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with
14+
#
15+
# composer phpstan:baselines -- --identifier=booleanAnd.leftAlwaysTrue
16+
#
17+
# which reruns the analysis with this file suppressed so the errors surface again.
18+
19+
parameters:
20+
ignoreErrors:
21+
-
22+
message: '#^Left side of && is always true\.$#'
23+
identifier: booleanAnd.leftAlwaysTrue
24+
count: 1
25+
path: ../../../src/wp-admin/network/users.php
26+
-
27+
message: '#^Left side of && is always true\.$#'
28+
identifier: booleanAnd.leftAlwaysTrue
29+
count: 1
30+
path: ../../../src/wp-admin/themes.php
31+
-
32+
message: '#^Left side of && is always true\.$#'
33+
identifier: booleanAnd.leftAlwaysTrue
34+
count: 1
35+
path: ../../../src/wp-includes/block-template-utils.php
36+
-
37+
message: '#^Left side of && is always true\.$#'
38+
identifier: booleanAnd.leftAlwaysTrue
39+
count: 1
40+
path: ../../../src/wp-includes/canonical.php
41+
-
42+
message: '#^Left side of && is always true\.$#'
43+
identifier: booleanAnd.leftAlwaysTrue
44+
count: 1
45+
path: ../../../src/wp-includes/html-api/class-wp-html-processor.php
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# PHPStan baseline for the `booleanAnd.rightAlwaysFalse` errors in WordPress core.
2+
#
3+
# https://phpstan.org/error-identifiers/booleanAnd.rightAlwaysFalse
4+
#
5+
# Each entry is scoped to a single file and carries an exact occurrence count,
6+
# so that a new instance is reported as a new error rather than being absorbed
7+
# silently. Fixing an occurrence therefore means decrementing or removing its
8+
# entry here as part of the same change.
9+
#
10+
# The goal is to empty this file and delete it, along with the `includes` entry
11+
# for it in phpstan.neon.dist.
12+
#
13+
# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with
14+
#
15+
# composer phpstan:baselines -- --identifier=booleanAnd.rightAlwaysFalse
16+
#
17+
# which reruns the analysis with this file suppressed so the errors surface again.
18+
19+
parameters:
20+
ignoreErrors:
21+
-
22+
message: '#^Right side of && is always false\.$#'
23+
identifier: booleanAnd.rightAlwaysFalse
24+
count: 1
25+
path: ../../../src/wp-includes/class-wpdb.php
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# PHPStan baseline for the `booleanAnd.rightAlwaysTrue` errors in WordPress core.
2+
#
3+
# https://phpstan.org/error-identifiers/booleanAnd.rightAlwaysTrue
4+
#
5+
# Each entry is scoped to a single file and carries an exact occurrence count,
6+
# so that a new instance is reported as a new error rather than being absorbed
7+
# silently. Fixing an occurrence therefore means decrementing or removing its
8+
# entry here as part of the same change.
9+
#
10+
# The goal is to empty this file and delete it, along with the `includes` entry
11+
# for it in phpstan.neon.dist.
12+
#
13+
# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with
14+
#
15+
# composer phpstan:baselines -- --identifier=booleanAnd.rightAlwaysTrue
16+
#
17+
# which reruns the analysis with this file suppressed so the errors surface again.
18+
19+
parameters:
20+
ignoreErrors:
21+
-
22+
message: '#^Right side of && is always true\.$#'
23+
identifier: booleanAnd.rightAlwaysTrue
24+
count: 1
25+
path: ../../../src/wp-admin/includes/class-wp-site-health.php
26+
-
27+
message: '#^Right side of && is always true\.$#'
28+
identifier: booleanAnd.rightAlwaysTrue
29+
count: 1
30+
path: ../../../src/wp-admin/includes/schema.php
31+
-
32+
message: '#^Right side of && is always true\.$#'
33+
identifier: booleanAnd.rightAlwaysTrue
34+
count: 1
35+
path: ../../../src/wp-content/themes/twentynineteen/header.php
36+
-
37+
message: '#^Right side of && is always true\.$#'
38+
identifier: booleanAnd.rightAlwaysTrue
39+
count: 1
40+
path: ../../../src/wp-includes/block-supports/typography.php
41+
-
42+
message: '#^Right side of && is always true\.$#'
43+
identifier: booleanAnd.rightAlwaysTrue
44+
count: 1
45+
path: ../../../src/wp-includes/class-wp-walker.php
46+
-
47+
message: '#^Right side of && is always true\.$#'
48+
identifier: booleanAnd.rightAlwaysTrue
49+
count: 2
50+
path: ../../../src/wp-includes/functions.php
51+
-
52+
message: '#^Right side of && is always true\.$#'
53+
identifier: booleanAnd.rightAlwaysTrue
54+
count: 3
55+
path: ../../../src/wp-includes/l10n.php
56+
-
57+
message: '#^Right side of && is always true\.$#'
58+
identifier: booleanAnd.rightAlwaysTrue
59+
count: 4
60+
path: ../../../src/wp-includes/load.php
61+
-
62+
message: '#^Right side of && is always true\.$#'
63+
identifier: booleanAnd.rightAlwaysTrue
64+
count: 2
65+
path: ../../../src/wp-includes/user.php
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# PHPStan baseline for the `booleanNot.alwaysFalse` errors in WordPress core.
2+
#
3+
# https://phpstan.org/error-identifiers/booleanNot.alwaysFalse
4+
#
5+
# Each entry is scoped to a single file and carries an exact occurrence count,
6+
# so that a new instance is reported as a new error rather than being absorbed
7+
# silently. Fixing an occurrence therefore means decrementing or removing its
8+
# entry here as part of the same change.
9+
#
10+
# The goal is to empty this file and delete it, along with the `includes` entry
11+
# for it in phpstan.neon.dist.
12+
#
13+
# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with
14+
#
15+
# composer phpstan:baselines -- --identifier=booleanNot.alwaysFalse
16+
#
17+
# which reruns the analysis with this file suppressed so the errors surface again.
18+
19+
parameters:
20+
ignoreErrors:
21+
-
22+
message: '#^Negated boolean expression is always false\.$#'
23+
identifier: booleanNot.alwaysFalse
24+
count: 1
25+
path: ../../../src/wp-admin/includes/theme.php
26+
-
27+
message: '#^Negated boolean expression is always false\.$#'
28+
identifier: booleanNot.alwaysFalse
29+
count: 1
30+
path: ../../../src/wp-admin/link-manager.php
31+
-
32+
message: '#^Negated boolean expression is always false\.$#'
33+
identifier: booleanNot.alwaysFalse
34+
count: 2
35+
path: ../../../src/wp-admin/network/users.php
36+
-
37+
message: '#^Negated boolean expression is always false\.$#'
38+
identifier: booleanNot.alwaysFalse
39+
count: 1
40+
path: ../../../src/wp-admin/plugins.php
41+
-
42+
message: '#^Negated boolean expression is always false\.$#'
43+
identifier: booleanNot.alwaysFalse
44+
count: 1
45+
path: ../../../src/wp-includes/class-wp-comment-query.php
46+
-
47+
message: '#^Negated boolean expression is always false\.$#'
48+
identifier: booleanNot.alwaysFalse
49+
count: 1
50+
path: ../../../src/wp-includes/nav-menu.php
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# PHPStan baseline for the `booleanNot.alwaysTrue` errors in WordPress core.
2+
#
3+
# https://phpstan.org/error-identifiers/booleanNot.alwaysTrue
4+
#
5+
# Each entry is scoped to a single file and carries an exact occurrence count,
6+
# so that a new instance is reported as a new error rather than being absorbed
7+
# silently. Fixing an occurrence therefore means decrementing or removing its
8+
# entry here as part of the same change.
9+
#
10+
# The goal is to empty this file and delete it, along with the `includes` entry
11+
# for it in phpstan.neon.dist.
12+
#
13+
# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with
14+
#
15+
# composer phpstan:baselines -- --identifier=booleanNot.alwaysTrue
16+
#
17+
# which reruns the analysis with this file suppressed so the errors surface again.
18+
19+
parameters:
20+
ignoreErrors:
21+
-
22+
message: '#^Negated boolean expression is always true\.$#'
23+
identifier: booleanNot.alwaysTrue
24+
count: 1
25+
path: ../../../src/wp-admin/includes/class-custom-image-header.php
26+
-
27+
message: '#^Negated boolean expression is always true\.$#'
28+
identifier: booleanNot.alwaysTrue
29+
count: 1
30+
path: ../../../src/wp-admin/includes/class-language-pack-upgrader.php
31+
-
32+
message: '#^Negated boolean expression is always true\.$#'
33+
identifier: booleanNot.alwaysTrue
34+
count: 1
35+
path: ../../../src/wp-admin/includes/class-wp-upgrader.php
36+
-
37+
message: '#^Negated boolean expression is always true\.$#'
38+
identifier: booleanNot.alwaysTrue
39+
count: 1
40+
path: ../../../src/wp-admin/includes/file.php
41+
-
42+
message: '#^Negated boolean expression is always true\.$#'
43+
identifier: booleanNot.alwaysTrue
44+
count: 1
45+
path: ../../../src/wp-includes/class-wp-block-templates-registry.php
46+
-
47+
message: '#^Negated boolean expression is always true\.$#'
48+
identifier: booleanNot.alwaysTrue
49+
count: 1
50+
path: ../../../src/wp-includes/class-wp-block.php
51+
-
52+
message: '#^Negated boolean expression is always true\.$#'
53+
identifier: booleanNot.alwaysTrue
54+
count: 1
55+
path: ../../../src/wp-includes/general-template.php
56+
-
57+
message: '#^Negated boolean expression is always true\.$#'
58+
identifier: booleanNot.alwaysTrue
59+
count: 1
60+
path: ../../../src/wp-includes/option.php

0 commit comments

Comments
 (0)