Make WordPress Core


Ignore:
Timestamp:
05/02/2026 05:16:01 AM (4 months ago)
Author:
westonruter
Message:

Build/Test Tools: Honor @global docblock tags in PHPStan analysis.

This adds a PHPStan extension with a parser-node visitor that bridges WordPress core's @global Type $varname PHPDoc convention to PHPStan's variable type resolution, eliminating 3,784 spurious errors caused by globals resolving as mixed when on rule level 10 (out of 40,069 errors total, so a 9.4% reduction). This avoids the need to add /** @var Type $varname */ annotations with each global variable.

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

Props westonruter, apermo, szepeviktor.
See #64898.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpstan/base.neon

    r61873 r62292  
    44#
    55# https://phpstan.org/config-reference
     6
     7services:
     8        # Bridges WordPress core's `@global Type $varname` function docblock convention to
     9        # PHPStan's variable type resolution. See tests/phpstan/GlobalDocBlockVisitor.php.
     10        -
     11                class: WordPress\PHPStan\GlobalDocBlockVisitor
     12                tags:
     13                        - phpstan.parser.richParserNodeVisitor
    614
    715parameters:
     
    9199                - ../../src/wp-trackback.php
    92100                - ../../src/xmlrpc.php
     101                - GlobalDocBlockVisitor.php
    93102        bootstrapFiles:
    94103                - bootstrap.php
Note: See TracChangeset for help on using the changeset viewer.