Skip to content

Commit 38f2bf2

Browse files
westonruterclaude
andcommitted
Build/Test Tools: Simplify the @global type pattern in GlobalDocBlockVisitor.
`(\S+(?:\s*\|\s*\S+)*)` was over-engineered: it explicitly handled spaced unions like `WP_User | WP_Error` but failed to capture types with internal whitespace such as generics (`array<string, int>`). `(\S.*?)` — anchored on a non-whitespace start and reluctantly matching up to the next `\s+\$\w+` — is functionally equivalent for every type form the alternation already handled, while also correctly capturing types that contain spaces. Whitespace is still collapsed before storing the type. Net effect: 12 additional `@global` tags are now recognized in the codebase. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent 24a9df9 commit 38f2bf2

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

tests/phpstan/GlobalDocBlockVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public function leaveNode( Node $node ): ?Node {
144144
*/
145145
private function parse_global_tags( string $docblock ): array {
146146
$map = array();
147-
if ( preg_match_all( '/@global\s+(?P<type>\S+(?:\s*\|\s*\S+)*)\s+\$(?P<variable>\w+)/', $docblock, $matches, PREG_SET_ORDER ) > 0 ) {
147+
if ( preg_match_all( '/@global\s+(?P<type>\S.*?)\s+\$(?P<variable>\w+)/', $docblock, $matches, PREG_SET_ORDER ) > 0 ) {
148148
foreach ( $matches as $match ) {
149149
$type = preg_replace( '/\s+/', '', $match['type'] );
150150
assert( is_string( $type ) && '' !== $type );

0 commit comments

Comments
 (0)