Skip to content

Commit 3ecb392

Browse files
committed
Code Quality: Annotate HTML API's parse_next_tag() as "impure" for PHPStan.
PHPStan infers the `WP_HTML_Tag_Processor::parse_next_tag()` method as pure, so the `STATE_READY` value narrowed onto `$parser_state` before the call survives across it, even though the method reassigns that property throughout its body. Every state comparison that follows in the `base_class_next_token()` method is then decided at analysis time rather than at runtime: both `&&` operands resolve to `true`, the early `return true` is treated as unconditional, and the remainder of the method is analyzed as unreachable. This in turn leaves `skip_rawtext()` and `skip_script_data()` reported as uncalled and `$skip_newline_at` as never assigned an `int`. Adding `@phpstan-impure`, the annotation PHPStan's own tip recommends, resolves ten baselined errors across six identifiers; `next_tag()` in the same class already carries it. This empties the `booleanAnd.alwaysTrue` and `property.unusedType` baselines, so both files are removed along with their `includes` entries in `phpstan.neon.dist`. Developed in WordPress#13057. Follow-up to r61934, r63023. Props tstokes8040. See #65817. git-svn-id: https://develop.svn.wordpress.org/trunk@63301 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 36af6b1 commit 3ecb392

8 files changed

Lines changed: 2 additions & 87 deletions

‎phpstan.neon.dist‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ includes:
2929
- tests/phpstan/baselines/assign.propertyType.neon
3030
- tests/phpstan/baselines/binaryOp.invalid.neon
3131
- tests/phpstan/baselines/booleanAnd.alwaysFalse.neon
32-
- tests/phpstan/baselines/booleanAnd.alwaysTrue.neon
3332
- tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon
3433
- tests/phpstan/baselines/booleanAnd.rightAlwaysTrue.neon
3534
- tests/phpstan/baselines/booleanNot.alwaysFalse.neon
@@ -80,7 +79,6 @@ includes:
8079
- tests/phpstan/baselines/property.phpDocType.neon
8180
- tests/phpstan/baselines/property.private.neon
8281
- tests/phpstan/baselines/property.protected.neon
83-
- tests/phpstan/baselines/property.unusedType.neon
8482
- tests/phpstan/baselines/return.empty.neon
8583
- tests/phpstan/baselines/return.missing.neon
8684
- tests/phpstan/baselines/return.type.neon

‎src/wp-includes/html-api/class-wp-html-tag-processor.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,6 +1728,8 @@ private function skip_script_data(): bool {
17281728
* @ignore
17291729
*
17301730
* @return bool Whether a tag was found before the end of the document.
1731+
*
1732+
* @phpstan-impure
17311733
*/
17321734
private function parse_next_tag(): bool {
17331735
$this->after_tag();

‎tests/phpstan/baselines/booleanAnd.alwaysTrue.neon‎

Lines changed: 0 additions & 25 deletions
This file was deleted.

‎tests/phpstan/baselines/deadCode.unreachable.neon‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,6 @@ parameters:
288288
identifier: deadCode.unreachable
289289
count: 31
290290
path: ../../../src/wp-includes/html-api/class-wp-html-processor.php
291-
-
292-
message: '#^Unreachable statement \- code above always terminates\.$#'
293-
identifier: deadCode.unreachable
294-
count: 1
295-
path: ../../../src/wp-includes/html-api/class-wp-html-tag-processor.php
296291
-
297292
message: '#^Unreachable statement \- code above always terminates\.$#'
298293
identifier: deadCode.unreachable

‎tests/phpstan/baselines/identical.alwaysFalse.neon‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ parameters:
2828
identifier: identical.alwaysFalse
2929
count: 1
3030
path: ../../../src/wp-includes/html-api/class-wp-html-processor.php
31-
-
32-
message: '#^Strict comparison using \=\=\= between ''STATE_INCOMPLETE…'' and ''STATE_READY'' will always evaluate to false\.$#'
33-
identifier: identical.alwaysFalse
34-
count: 1
35-
path: ../../../src/wp-includes/html-api/class-wp-html-tag-processor.php
3631
-
3732
message: '#^Strict comparison using \=\=\= between 3000000000 and 2147483647 will always evaluate to false\.$#'
3833
identifier: identical.alwaysFalse

‎tests/phpstan/baselines/method.unused.neon‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,3 @@ parameters:
3333
identifier: method.unused
3434
count: 1
3535
path: ../../../src/wp-includes/class-wp-script-modules.php
36-
-
37-
message: '#^Method WP_HTML_Tag_Processor\:\:skip_rawtext\(\) is unused\.$#'
38-
identifier: method.unused
39-
count: 1
40-
path: ../../../src/wp-includes/html-api/class-wp-html-tag-processor.php
41-
-
42-
message: '#^Method WP_HTML_Tag_Processor\:\:skip_script_data\(\) is unused\.$#'
43-
identifier: method.unused
44-
count: 1
45-
path: ../../../src/wp-includes/html-api/class-wp-html-tag-processor.php

‎tests/phpstan/baselines/notIdentical.alwaysTrue.neon‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,6 @@ parameters:
3838
identifier: notIdentical.alwaysTrue
3939
count: 1
4040
path: ../../../src/wp-includes/functions.php
41-
-
42-
message: '#^Strict comparison using \!\=\= between ''STATE_COMPLETE'' and ''STATE_READY'' will always evaluate to true\.$#'
43-
identifier: notIdentical.alwaysTrue
44-
count: 1
45-
path: ../../../src/wp-includes/html-api/class-wp-html-tag-processor.php
46-
-
47-
message: '#^Strict comparison using \!\=\= between ''STATE_INCOMPLETE…'' and ''STATE_READY'' will always evaluate to true\.$#'
48-
identifier: notIdentical.alwaysTrue
49-
count: 1
50-
path: ../../../src/wp-includes/html-api/class-wp-html-tag-processor.php
51-
-
52-
message: '#^Strict comparison using \!\=\= between ''STATE_MATCHED_TAG'' and ''STATE_READY'' will always evaluate to true\.$#'
53-
identifier: notIdentical.alwaysTrue
54-
count: 1
55-
path: ../../../src/wp-includes/html-api/class-wp-html-tag-processor.php
5641
-
5742
message: '#^Strict comparison using \!\=\= between 0 and int\<min, \-1\>\|int\<1, max\> will always evaluate to true\.$#'
5843
identifier: notIdentical.alwaysTrue

‎tests/phpstan/baselines/property.unusedType.neon‎

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)