@@ -44,7 +44,7 @@ final class GlobalDocBlockVisitor extends NodeVisitorAbstract {
4444 *
4545 * Each frame maps variable names (without `$`) to their declared type.
4646 *
47- * @var list<array<string, string>>
47+ * @var list<array<non-empty- string, non-empty- string>>
4848 */
4949 private array $ stack = array ();
5050
@@ -140,13 +140,15 @@ public function leaveNode( Node $node ): ?Node {
140140 * Whitespace inside the type is collapsed.
141141 *
142142 * @param string $docblock Raw docblock text including `/**` markers.
143- * @return array<string, string> Map of variable name (no `$`) to type.
143+ * @return array<non-empty- string, non-empty- string> Map of variable name (no `$`) to type.
144144 */
145145 private function parse_global_tags ( string $ docblock ): array {
146146 $ map = array ();
147- if ( preg_match_all ( '/@global\s+(\S+(?:\s*\|\s*\S+)*)\s+\$(\w+)/ ' , $ docblock , $ matches , PREG_SET_ORDER ) > 0 ) {
147+ if ( preg_match_all ( '/@global\s+(?P<type> \S+(?:\s*\|\s*\S+)*)\s+\$(?P<variable> \w+)/ ' , $ docblock , $ matches , PREG_SET_ORDER ) > 0 ) {
148148 foreach ( $ matches as $ match ) {
149- $ map [ $ match [2 ] ] = (string ) preg_replace ( '/\s+/ ' , '' , $ match [1 ] );
149+ $ type = preg_replace ( '/\s+/ ' , '' , $ match ['type ' ] );
150+ assert ( is_string ( $ type ) && '' !== $ type );
151+ $ map [ $ match ['variable ' ] ] = $ type ;
150152 }
151153 }
152154 return $ map ;
0 commit comments