5
5
use PhpParser \Comment \Doc ;
6
6
use PhpParser \Node \Stmt ;
7
7
use PhpParser \Node \Stmt \Class_ ;
8
+ use PhpParser \Node \NullableType ;
8
9
use PhpParser \Node \Stmt \ClassMethod ;
9
10
use PhpParser \Node \Stmt \Namespace_ ;
10
11
use PhpParser \Node \Stmt \Use_ ;
@@ -93,8 +94,12 @@ protected function processStatements(array $statements, $prefix = '')
93
94
94
95
$ type = $ method ->returnType ;
95
96
96
- if (!is_null ($ type )) {
97
- $ type = (string )$ type ;
97
+ if (!$ method ->returnType instanceof NullableType) {
98
+ if (!is_null ($ type )) {
99
+ $ type = (string )$ type ;
100
+ }
101
+ } else {
102
+ $ type = (string )$ type ->type ;
98
103
}
99
104
100
105
if (isset ($ uses [$ type ])) {
@@ -103,6 +108,10 @@ protected function processStatements(array $statements, $prefix = '')
103
108
104
109
$ type = substr ($ type , 0 , 1 ) == '\\' ? substr ($ type , 1 ) : $ type ;
105
110
111
+ if ($ method ->returnType instanceof NullableType) {
112
+ $ type = ['null ' , $ type ];
113
+ sort ($ type );
114
+ }
106
115
107
116
$ thisMethod = [
108
117
'file ' => $ this ->file ,
@@ -117,8 +126,12 @@ protected function processStatements(array $statements, $prefix = '')
117
126
foreach ($ method ->params as $ param ) {
118
127
$ type = $ param ->type ;
119
128
120
- if (!is_null ($ type )) {
121
- $ type = (string )$ type ;
129
+ if (!$ type instanceof NullableType) {
130
+ if (!is_null ($ type )) {
131
+ $ type = (string )$ type ;
132
+ }
133
+ } else {
134
+ $ type = (string )$ type ->type ;
122
135
}
123
136
124
137
if (isset ($ uses [$ type ])) {
@@ -177,13 +190,14 @@ protected function processDocblock($text, array $uses = [])
177
190
$ type = (string )$ type ;
178
191
}
179
192
180
- if (isset ($ uses [$ type ])) {
181
- $ type = $ uses [$ type ];
193
+ $ types = [];
194
+ foreach (explode ('| ' , $ type ) as $ tmpType ) {
195
+ if (isset ($ uses [$ tmpType ])) {
196
+ $ tmpType = $ uses [$ tmpType ];
197
+ }
198
+ $ types [] = substr ($ tmpType , 0 , 1 ) == '\\' ? substr ($ tmpType , 1 ) : $ tmpType ;
182
199
}
183
-
184
- $ type = substr ($ type , 0 , 1 ) == '\\' ? substr ($ type , 1 ) : $ type ;
185
-
186
- $ rtn ['params ' ][$ param ['var ' ]] = $ type ;
200
+ $ rtn ['params ' ][$ param ['var ' ]] = implode ('| ' , $ types );
187
201
}
188
202
}
189
203
@@ -196,13 +210,14 @@ protected function processDocblock($text, array $uses = [])
196
210
$ type = (string )$ type ;
197
211
}
198
212
199
- if (isset ($ uses [$ type ])) {
200
- $ type = $ uses [$ type ];
213
+ $ types = [];
214
+ foreach (explode ('| ' , $ type ) as $ tmpType ) {
215
+ if (isset ($ uses [$ tmpType ])) {
216
+ $ tmpType = $ uses [$ tmpType ];
217
+ }
218
+ $ types [] = substr ($ tmpType , 0 , 1 ) == '\\' ? substr ($ tmpType , 1 ) : $ tmpType ;
201
219
}
202
-
203
- $ type = substr ($ type , 0 , 1 ) == '\\' ? substr ($ type , 1 ) : $ type ;
204
-
205
- $ rtn ['return ' ] = $ type ;
220
+ $ rtn ['return ' ] = implode ('| ' , $ types );
206
221
}
207
222
208
223
return $ rtn ;
0 commit comments