@@ -209,7 +209,7 @@ public function getVariants(): array
209209 null ,
210210 $ this ->getParameters (),
211211 $ this ->isVariadic (),
212- $ this -> getReturnType () ,
212+ null ,
213213 $ this ->getPhpDocReturnType (),
214214 $ this ->getNativeReturnType (),
215215 ),
@@ -263,52 +263,51 @@ public function isPublic(): bool
263263
264264 private function getReturnType (): Type
265265 {
266- if ($ this ->returnType === null ) {
267- $ name = strtolower ($ this ->getName ());
266+ return $ this ->returnType ??= TypehintHelper ::decideType (
267+ $ this ->getNativeReturnType (),
268+ $ this ->phpDocReturnType ,
269+ );
270+ }
271+
272+ private function getPhpDocReturnType (): Type
273+ {
274+ if ($ this ->phpDocReturnType !== null ) {
275+ return $ this ->phpDocReturnType ;
276+ }
277+
278+ return new MixedType ();
279+ }
280+
281+ private function getNativeReturnType (): Type
282+ {
283+ if ($ this ->nativeReturnType === null ) {
268284 $ returnType = $ this ->reflection ->getReturnType ();
269285 if ($ returnType === null ) {
286+ $ name = strtolower ($ this ->getName ());
270287 if (in_array ($ name , ['__construct ' , '__destruct ' , '__unset ' , '__wakeup ' , '__clone ' ], true )) {
271- return $ this ->returnType = TypehintHelper :: decideType ( new VoidType (), $ this -> phpDocReturnType );
288+ return $ this ->nativeReturnType = new VoidType ();
272289 }
273290 if ($ name === '__tostring ' ) {
274- return $ this ->returnType = TypehintHelper :: decideType ( new StringType (), $ this -> phpDocReturnType );
291+ return $ this ->nativeReturnType = new StringType ();
275292 }
276293 if ($ name === '__isset ' ) {
277- return $ this ->returnType = TypehintHelper :: decideType ( new BooleanType (), $ this -> phpDocReturnType );
294+ return $ this ->nativeReturnType = new BooleanType ();
278295 }
279296 if ($ name === '__sleep ' ) {
280- return $ this ->returnType = TypehintHelper :: decideType ( new ArrayType (new IntegerType (), new StringType ()), $ this -> phpDocReturnType );
297+ return $ this ->nativeReturnType = new ArrayType (new IntegerType (), new StringType ());
281298 }
282299 if ($ name === '__set_state ' ) {
283- return $ this ->returnType = TypehintHelper :: decideType ( new ObjectWithoutClassType (), $ this -> phpDocReturnType );
300+ return $ this ->nativeReturnType = new ObjectWithoutClassType ();
284301 }
285302 }
286303
287- $ this ->returnType = TypehintHelper ::decideTypeFromReflection (
304+ $ this ->nativeReturnType = TypehintHelper ::decideTypeFromReflection (
288305 $ returnType ,
289- $ this ->phpDocReturnType ,
290- $ this ->declaringClass ,
306+ selfClass: $ this ->declaringClass ,
291307 );
292308 }
293309
294- return $ this ->returnType ;
295- }
296-
297- private function getPhpDocReturnType (): Type
298- {
299- if ($ this ->phpDocReturnType !== null ) {
300- return $ this ->phpDocReturnType ;
301- }
302-
303- return new MixedType ();
304- }
305-
306- private function getNativeReturnType (): Type
307- {
308- return $ this ->nativeReturnType ??= TypehintHelper ::decideTypeFromReflection (
309- $ this ->reflection ->getReturnType (),
310- selfClass: $ this ->declaringClass ,
311- );
310+ return $ this ->nativeReturnType ;
312311 }
313312
314313 public function getDeprecatedDescription (): ?string
0 commit comments