@@ -92,55 +92,68 @@ protected function processStatements(array $statements, $prefix = '')
92
92
93
93
$ fullMethodName = $ fullClassName . ':: ' . (string )$ method ->name ;
94
94
95
- $ type = $ method ->returnType ;
95
+ $ returnType = $ method ->returnType ;
96
96
97
97
if (!$ method ->returnType instanceof NullableType) {
98
- if (!is_null ($ type )) {
99
- $ type = (string )$ type ;
98
+ if (!is_null ($ returnType )) {
99
+ $ returnType = (string )$ returnType ;
100
100
}
101
101
} else {
102
- $ type = (string )$ type ->type ;
102
+ $ returnType = (string )$ returnType ->type ;
103
103
}
104
104
105
- if (isset ($ uses [$ type ])) {
106
- $ type = $ uses [$ type ];
105
+ if (isset ($ uses [$ returnType ])) {
106
+ $ returnType = $ uses [$ returnType ];
107
107
}
108
108
109
- $ type = substr ($ type , 0 , 1 ) == '\\' ? substr ($ type , 1 ) : $ type ;
109
+ $ returnType = substr ($ returnType , 0 , 1 ) === '\\' ? substr ($ returnType , 1 ) : $ returnType ;
110
110
111
111
if ($ method ->returnType instanceof NullableType) {
112
- $ type = ['null ' , $ type ];
113
- sort ($ type );
112
+ $ returnType = [$ returnType , 'null ' ];
114
113
}
115
114
116
115
$ thisMethod = [
117
116
'file ' => $ this ->file ,
118
117
'class ' => $ fullClassName ,
119
118
'name ' => (string )$ method ->name ,
120
119
'line ' => $ method ->getAttribute ('startLine ' ),
121
- 'return ' => $ type ,
120
+ 'return ' => $ returnType ,
122
121
'params ' => [],
123
122
'docblock ' => $ this ->getDocblock ($ method , $ uses ),
124
123
];
125
124
126
125
foreach ($ method ->params as $ param ) {
127
- $ type = $ param ->type ;
126
+ $ paramType = $ param ->type ;
128
127
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 ;
132
131
}
133
132
} else {
134
- $ type = (string )$ type ->type ;
133
+ $ paramType = (string )$ paramType ->type ;
135
134
}
136
135
137
- if (isset ($ uses [$ type ])) {
138
- $ type = $ uses [$ type ];
136
+ if (isset ($ uses [$ paramType ])) {
137
+ $ paramType = $ uses [$ paramType ];
139
138
}
140
139
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 ]);
142
155
143
- $ thisMethod ['params ' ]['$ ' .$ param ->name ] = $ type ;
156
+ $ thisMethod ['params ' ]['$ ' .$ param ->name ] = $ paramType ;
144
157
}
145
158
146
159
$ this ->methods [$ fullMethodName ] = $ thisMethod ;
@@ -195,7 +208,7 @@ protected function processDocblock($text, array $uses = [])
195
208
if (isset ($ uses [$ tmpType ])) {
196
209
$ tmpType = $ uses [$ tmpType ];
197
210
}
198
- $ types [] = substr ($ tmpType , 0 , 1 ) == '\\' ? substr ($ tmpType , 1 ) : $ tmpType ;
211
+ $ types [] = substr ($ tmpType , 0 , 1 ) === '\\' ? substr ($ tmpType , 1 ) : $ tmpType ;
199
212
}
200
213
$ rtn ['params ' ][$ param ['var ' ]] = implode ('| ' , $ types );
201
214
}
@@ -215,7 +228,7 @@ protected function processDocblock($text, array $uses = [])
215
228
if (isset ($ uses [$ tmpType ])) {
216
229
$ tmpType = $ uses [$ tmpType ];
217
230
}
218
- $ types [] = substr ($ tmpType , 0 , 1 ) == '\\' ? substr ($ tmpType , 1 ) : $ tmpType ;
231
+ $ types [] = substr ($ tmpType , 0 , 1 ) === '\\' ? substr ($ tmpType , 1 ) : $ tmpType ;
219
232
}
220
233
$ rtn ['return ' ] = implode ('| ' , $ types );
221
234
}
0 commit comments