Make WordPress Core

Changeset 63301


Ignore:
Timestamp:
08/14/2026 06:22:35 PM (4 weeks ago)
Author:
westonruter
Message:

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 https://github.com/WordPress/wordpress-develop/pull/13057.
Follow-up to r61934, r63023.

Props tstokes8040.
See #65817.

Location:
trunk
Files:
2 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/phpstan.neon.dist

    r63191 r63301  
    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
     
    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
  • trunk/src/wp-includes/html-api/class-wp-html-tag-processor.php

    r63293 r63301  
    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 {
  • trunk/tests/phpstan/baselines/deadCode.unreachable.neon

    r63023 r63301  
    293293                        identifier: deadCode.unreachable
    294294                        count: 1
    295                         path: ../../../src/wp-includes/html-api/class-wp-html-tag-processor.php
    296                 -
    297                         message: '#^Unreachable statement \- code above always terminates\.$#'
    298                         identifier: deadCode.unreachable
    299                         count: 1
    300295                        path: ../../../src/wp-includes/pluggable.php
    301296                -
  • trunk/tests/phpstan/baselines/identical.alwaysFalse.neon

    r63023 r63301  
    3030                        path: ../../../src/wp-includes/html-api/class-wp-html-processor.php
    3131                -
    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
    36                 -
    3732                        message: '#^Strict comparison using \=\=\= between 3000000000 and 2147483647 will always evaluate to false\.$#'
    3833                        identifier: identical.alwaysFalse
  • trunk/tests/phpstan/baselines/method.unused.neon

    r63023 r63301  
    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
  • trunk/tests/phpstan/baselines/notIdentical.alwaysTrue.neon

    r63158 r63301  
    4040                        path: ../../../src/wp-includes/functions.php
    4141                -
    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
    56                 -
    5742                        message: '#^Strict comparison using \!\=\= between 0 and int\<min, \-1\>\|int\<1, max\> will always evaluate to true\.$#'
    5843                        identifier: notIdentical.alwaysTrue
Note: See TracChangeset for help on using the changeset viewer.