Skip to content

Commit 4be1db5

Browse files
committed
Code Quality: Annotate WP_HTML_Processor::next_token() as "impure".
PHPStan infers `WP_HTML_Processor::next_token()` as pure, so the result of `is_tag_closer()` before the matching-closer loop in the block bindings processor's `replace_rich_text()` method survives across the loop, even though each `next_token()` call advances the parser to a different token. The `||` in the check after the loop is then reported as always true, the negation within it as always true, and the code that follows as unreachable. Adding `@phpstan-impure`, as was done for `WP_HTML_Tag_Processor::next_tag()` in r61934 and for `WP_HTML_Tag_Processor::parse_next_tag()` in r63301, resolves all three baselined errors. This empties the `booleanOr.alwaysTrue` baseline, so the file is removed along with its `includes` entry in `phpstan.neon.dist`. Developed in WordPress#14037. Follow-up to r61934, r63023, r63301. Props huzaifaalmesbah, rejaulalomkhan, tstokes8040. See #65817. git-svn-id: https://develop.svn.wordpress.org/trunk@64335 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 4b66251 commit 4be1db5

5 files changed

Lines changed: 2 additions & 36 deletions

File tree

‎phpstan.neon.dist‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ includes:
3232
- tests/phpstan/baselines/booleanNot.alwaysFalse.neon
3333
- tests/phpstan/baselines/booleanNot.alwaysTrue.neon
3434
- tests/phpstan/baselines/booleanOr.alwaysFalse.neon
35-
- tests/phpstan/baselines/booleanOr.alwaysTrue.neon
3635
- tests/phpstan/baselines/class.notFound.neon
3736
- tests/phpstan/baselines/deadCode.unreachable.neon
3837
- tests/phpstan/baselines/empty.offset.neon

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,8 @@ public function next_tag( $query = null ): bool {
779779
* @since 6.7.2 Refactored so subclasses may extend.
780780
*
781781
* @return bool Whether a token was parsed.
782+
*
783+
* @phpstan-impure
782784
*/
783785
public function next_token(): bool {
784786
return $this->next_visitable_token();

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ parameters:
4343
identifier: booleanNot.alwaysTrue
4444
count: 1
4545
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
5146
-
5247
message: '#^Negated boolean expression is always true\.$#'
5348
identifier: booleanNot.alwaysTrue

‎tests/phpstan/baselines/booleanOr.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
@@ -48,11 +48,6 @@ parameters:
4848
identifier: deadCode.unreachable
4949
count: 1
5050
path: ../../../src/wp-includes/capabilities.php
51-
-
52-
message: '#^Unreachable statement \- code above always terminates\.$#'
53-
identifier: deadCode.unreachable
54-
count: 1
55-
path: ../../../src/wp-includes/class-wp-block.php
5651
-
5752
message: '#^Unreachable statement \- code above always terminates\.$#'
5853
identifier: deadCode.unreachable

0 commit comments

Comments
 (0)