File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -135,25 +135,30 @@ function parse_files( $files, $root ) {
135135 throw $ e ;
136136 }
137137
138- /*
139- * nikic/php-parser in version 3 started adding a namespace prefix
140- * at the start of global names, but this is different than how the
141- * documentation was previously generated. this removes those prefixes.
142- */
143- array_walk_recursive (
144- $ output ,
145- static function ( &$ value ) {
146- if ( ! is_string ( $ value ) || strlen ( $ value ) < 2 || '\\' !== $ value [0 ] ) {
147- return ;
148- }
138+ if ( true ) {
139+ /*
140+ * nikic/php-parser in version 3 started adding a namespace prefix
141+ * at the start of global names, but this is different than how the
142+ * documentation was previously generated. this removes those prefixes.
143+ */
144+ array_walk_recursive (
145+ $ output ,
146+ static function ( &$ value ) {
147+ if ( is_string ( $ value ) ) {
148+ // "\wp_kses()" -> "wp_kses()"
149+ $ without_global_namespace = preg_replace (
150+ '~(^|\p{Z}) \\\\([A-Z_a-z\x80-\xFF][0-9A-Z_a-z\x80-\xFF]*)(\p{Z}|$)~ ' ,
151+ '$1$2$3 ' ,
152+ $ value ,
153+ );
149154
150- // "\wp_kses()" -> "wp_kses()"
151- $ next_slash = strpos ( $ value , '\\' , 1 ) ;
152- if ( false === $ next_slash ) {
153- $ value = substr ( $ value , 1 );
155+ if ( $ value !== $ without_global_namespace ) {
156+ $ value = $ without_global_namespace ;
157+ }
158+ }
154159 }
155- }
156- );
160+ );
161+ }
157162
158163 return $ output ;
159164}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ $ output = json_decode ( file_get_contents ( 'php://stdin ' ), true );
4+
5+ array_walk_recursive (
6+ $ output ,
7+ static function ( &$ value , $ key ) {
8+ if ( 'line ' === $ key || 'end_line ' === $ key ) {
9+ $ value = 0 ;
10+ return ;
11+ }
12+
13+ if ( is_string ( $ value ) ) {
14+ // "\wp_kses()" -> "wp_kses()"
15+ $ without_global_namespace = preg_replace (
16+ '~(^|\p{Z}) \\\\([A-Z_a-z\x80-\xFF][0-9A-Z_a-z\x80-\xFF]*)(\p{Z}|$)~ ' ,
17+ '$1$2$3 ' ,
18+ $ value ,
19+ );
20+
21+ if ( $ value !== $ without_global_namespace ) {
22+ $ value = $ without_global_namespace ;
23+ }
24+ }
25+ }
26+ );
27+
28+ echo json_encode ( $ output , JSON_PRETTY_PRINT );
You can’t perform that action at this time.
0 commit comments