@@ -92,55 +92,68 @@ protected function processStatements(array $statements, $prefix = '')
9292
9393 $ fullMethodName = $ fullClassName . ':: ' . (string )$ method ->name ;
9494
95- $ type = $ method ->returnType ;
95+ $ returnType = $ method ->returnType ;
9696
9797 if (!$ method ->returnType instanceof NullableType) {
98- if (!is_null ($ type )) {
99- $ type = (string )$ type ;
98+ if (!is_null ($ returnType )) {
99+ $ returnType = (string )$ returnType ;
100100 }
101101 } else {
102- $ type = (string )$ type ->type ;
102+ $ returnType = (string )$ returnType ->type ;
103103 }
104104
105- if (isset ($ uses [$ type ])) {
106- $ type = $ uses [$ type ];
105+ if (isset ($ uses [$ returnType ])) {
106+ $ returnType = $ uses [$ returnType ];
107107 }
108108
109- $ type = substr ($ type , 0 , 1 ) == '\\' ? substr ($ type , 1 ) : $ type ;
109+ $ returnType = substr ($ returnType , 0 , 1 ) === '\\' ? substr ($ returnType , 1 ) : $ returnType ;
110110
111111 if ($ method ->returnType instanceof NullableType) {
112- $ type = ['null ' , $ type ];
113- sort ($ type );
112+ $ returnType = [$ returnType , 'null ' ];
114113 }
115114
116115 $ thisMethod = [
117116 'file ' => $ this ->file ,
118117 'class ' => $ fullClassName ,
119118 'name ' => (string )$ method ->name ,
120119 'line ' => $ method ->getAttribute ('startLine ' ),
121- 'return ' => $ type ,
120+ 'return ' => $ returnType ,
122121 'params ' => [],
123122 'docblock ' => $ this ->getDocblock ($ method , $ uses ),
124123 ];
125124
126125 foreach ($ method ->params as $ param ) {
127- $ type = $ param ->type ;
126+ $ paramType = $ param ->type ;
128127
129- if (!$ type instanceof NullableType) {
130- if (!is_null ($ type )) {
131- $ type = (string )$ type ;
128+ if (!$ param -> type instanceof NullableType) {
129+ if (!is_null ($ param -> type )) {
130+ $ paramType = (string )$ paramType ;
132131 }
133132 } else {
134- $ type = (string )$ type ->type ;
133+ $ paramType = (string )$ paramType ->type ;
135134 }
136135
137- if (isset ($ uses [$ type ])) {
138- $ type = $ uses [$ type ];
136+ if (isset ($ uses [$ paramType ])) {
137+ $ paramType = $ uses [$ paramType ];
139138 }
140139
141- $ type = substr ($ type , 0 , 1 ) == '\\' ? substr ($ type , 1 ) : $ type ;
140+ $ paramType = substr ($ paramType , 0 , 1 ) === '\\' ? substr ($ paramType , 1 ) : $ paramType ;
141+
142+ if (
143+ $ param ->type instanceof NullableType
144+ ) {
145+ $ paramType = [$ paramType , 'null ' ];
146+ } elseif (!empty ($ param ->default ->name ->parts [0 ]) && 'null ' === $ param ->default ->name ->parts [0 ]) {
147+ if (!is_null ($ param ->type )) {
148+ $ paramType = [$ paramType , 'null ' ];
149+ } else {
150+ $ paramType = ['<any> ' , 'null ' ];
151+ }
152+ }
153+
154+ var_dump ([$ param ->default ->name ->parts [0 ], $ paramType ]);
142155
143- $ thisMethod ['params ' ]['$ ' .$ param ->name ] = $ type ;
156+ $ thisMethod ['params ' ]['$ ' .$ param ->name ] = $ paramType ;
144157 }
145158
146159 $ this ->methods [$ fullMethodName ] = $ thisMethod ;
@@ -195,7 +208,7 @@ protected function processDocblock($text, array $uses = [])
195208 if (isset ($ uses [$ tmpType ])) {
196209 $ tmpType = $ uses [$ tmpType ];
197210 }
198- $ types [] = substr ($ tmpType , 0 , 1 ) == '\\' ? substr ($ tmpType , 1 ) : $ tmpType ;
211+ $ types [] = substr ($ tmpType , 0 , 1 ) === '\\' ? substr ($ tmpType , 1 ) : $ tmpType ;
199212 }
200213 $ rtn ['params ' ][$ param ['var ' ]] = implode ('| ' , $ types );
201214 }
@@ -215,7 +228,7 @@ protected function processDocblock($text, array $uses = [])
215228 if (isset ($ uses [$ tmpType ])) {
216229 $ tmpType = $ uses [$ tmpType ];
217230 }
218- $ types [] = substr ($ tmpType , 0 , 1 ) == '\\' ? substr ($ tmpType , 1 ) : $ tmpType ;
231+ $ types [] = substr ($ tmpType , 0 , 1 ) === '\\' ? substr ($ tmpType , 1 ) : $ tmpType ;
219232 }
220233 $ rtn ['return ' ] = implode ('| ' , $ types );
221234 }
0 commit comments