@@ -44,6 +44,82 @@ class File_Reflector extends FileReflector {
4444 */
4545 protected $ last_doc = null ;
4646
47+ public function __construct ( $ file , $ validate = false , $ encoding = 'utf-8 ' ) {
48+ parent ::__construct ( $ file , false /* Force validation off */ , $ encoding );
49+
50+ // Nullable types are unknown to the parser, pretend they don't exist.
51+ // The nullable type should be listed in the PHPDoc anyway.
52+ $ this ->contents = preg_replace_callback (
53+ '/(function [a-z0-9-_]+\([^{:]*?)\)(\:\s*\??\S+)?\s*[{;]/im ' ,
54+ static function ( $ m ) {
55+ return preg_replace ( '/\?(\S+)/ ' , '$1 ' , $ m [0 ] ) ?: $ m [0 ];
56+ },
57+ $ this ->contents
58+ );
59+
60+ // Inline callables... ( $var )( $param ) can usualy be rewritten as $var( $param ).
61+ $ this ->contents = preg_replace_callback (
62+ '/(?:\s)(\(\s*\$[^()]+\))(\(.+\))/ ' ,
63+ static function ( $ m ) {
64+ return trim ( $ m [1 ], '() ' ) . trim ( $ m [2 ] );
65+ },
66+ $ this ->contents
67+ );
68+
69+ // Short list() syntax...
70+ $ this ->contents = preg_replace_callback (
71+ '/(\s)\[(\s*\$[^();.*]{3,}?)\]\s*=/ism ' ,
72+ static function ( $ m ) {
73+ return $ m [1 ] . 'list( ' . $ m [2 ] . ' ) = ' ;
74+ },
75+ $ this ->contents
76+ );
77+
78+ // Visibility on constants
79+ $ this ->contents = preg_replace_callback (
80+ '/\b(public|protected|private)\s+const\s+/im ' ,
81+ static function ( $ m ) {
82+ return 'const ' ;
83+ },
84+ $ this ->contents
85+ );
86+
87+ // constant arrays weren't supported.
88+ $ this ->contents = preg_replace_callback (
89+ '/\b(?<!\$|\[)([A-Z_]{5,})\[ ([^]]+)\]/ ' ,
90+ function ( $ m ) {
91+ return '$ ' . $ m [1 ] . '[ ' . $ m [2 ] . '] ' ;
92+ },
93+ $ this ->contents
94+ );
95+
96+ // Static calls on static calls. Mostly in tests.
97+ $ this ->contents = preg_replace_callback (
98+ '/([\$\[\]_a-z]+)::([\$\[\]_a-z]+)::([\$\[\]_a-z]+)/ ' ,
99+ static function ( $ m ) {
100+ //var_dump( $m );
101+ if ( 'self ' === $ m [1 ] || 'static ' === $ m [1 ] ) {
102+ return '$this-> ' . $ m [2 ] . '-> ' . $ m [3 ];
103+ }
104+
105+ return $ m [1 ] . '-> ' . $ m [2 ]. '-> ' . $ m [3 ];
106+ },
107+ $ this ->contents
108+ );
109+
110+ // Static calls on function results. Mostly in tests.
111+ $ this ->contents = preg_replace_callback (
112+ '/([a-z_])\(\)::/ ' ,
113+ static function ( $ m ) {
114+ return $ m [1 ] . '()-> ' ;
115+ },
116+ $ this ->contents
117+ );
118+
119+ // Recalculate the hash, since we probably changed the contents.
120+ $ this ->hash = md5 ($ this ->contents );
121+ }
122+
47123 /**
48124 * Add hooks to the queue and update the node stack when we enter a node.
49125 *
0 commit comments