@@ -302,9 +302,30 @@ public function isPublic(): bool
302
302
private function getReturnType (): Type
303
303
{
304
304
if ($ this ->returnType === null ) {
305
- $ this ->returnType = TypehintHelper::decideType (
306
- $ this ->getNativeReturnType (),
305
+ $ name = strtolower ($ this ->getName ());
306
+ $ returnType = $ this ->reflection ->getReturnType ();
307
+ if ($ returnType === null ) {
308
+ if (in_array ($ name , ['__construct ' , '__destruct ' , '__unset ' , '__wakeup ' , '__clone ' ], true )) {
309
+ return $ this ->returnType = TypehintHelper::decideType (new VoidType (), $ this ->phpDocReturnType );
310
+ }
311
+ if ($ name === '__tostring ' ) {
312
+ return $ this ->returnType = TypehintHelper::decideType (new StringType (), $ this ->phpDocReturnType );
313
+ }
314
+ if ($ name === '__isset ' ) {
315
+ return $ this ->returnType = TypehintHelper::decideType (new BooleanType (), $ this ->phpDocReturnType );
316
+ }
317
+ if ($ name === '__sleep ' ) {
318
+ return $ this ->returnType = TypehintHelper::decideType (new ArrayType (new IntegerType (), new StringType ()), $ this ->phpDocReturnType );
319
+ }
320
+ if ($ name === '__set_state ' ) {
321
+ return $ this ->returnType = TypehintHelper::decideType (new ObjectWithoutClassType (), $ this ->phpDocReturnType );
322
+ }
323
+ }
324
+
325
+ $ this ->returnType = TypehintHelper::decideTypeFromReflection (
326
+ $ returnType ,
307
327
$ this ->phpDocReturnType ,
328
+ $ this ->declaringClass ,
308
329
);
309
330
}
310
331
@@ -323,28 +344,8 @@ private function getPhpDocReturnType(): Type
323
344
private function getNativeReturnType (): Type
324
345
{
325
346
if ($ this ->nativeReturnType === null ) {
326
- $ returnType = $ this ->reflection ->getReturnType ();
327
- if ($ returnType === null ) {
328
- $ name = strtolower ($ this ->getName ());
329
- if (in_array ($ this ->getName (), ['__construct ' , '__destruct ' , '__unset ' , '__wakeup ' , '__clone ' ], true )) {
330
- return $ this ->nativeReturnType = new VoidType ();
331
- }
332
- if ($ name === '__tostring ' ) {
333
- return $ this ->nativeReturnType = new StringType ();
334
- }
335
- if ($ name === '__isset ' ) {
336
- return $ this ->nativeReturnType = new BooleanType ();
337
- }
338
- if ($ name === '__sleep ' ) {
339
- return $ this ->nativeReturnType = new ArrayType (new IntegerType (), new StringType ());
340
- }
341
- if ($ name === '__set_state ' ) {
342
- return $ this ->nativeReturnType = new ObjectWithoutClassType ();
343
- }
344
- }
345
-
346
347
$ this ->nativeReturnType = TypehintHelper::decideTypeFromReflection (
347
- $ returnType ,
348
+ $ this -> reflection -> getReturnType () ,
348
349
null ,
349
350
$ this ->declaringClass ,
350
351
);
0 commit comments