setReturnsReference(strtolower($name) === '__get'); if (! $originalClass->hasMethod($name)) { return; } $originalMethod = $originalClass->getMethod($name); $originalReturnType = $originalMethod->getReturnType(); $this->setReturnsReference($originalMethod->returnsReference()); if ($originalReturnType instanceof ReflectionNamedType) { $this->setReturnType(($originalReturnType->allowsNull() && $originalReturnType->getName() !== 'mixed' ? '?' : '') . $originalReturnType->getName()); } elseif ($originalReturnType instanceof ReflectionUnionType || $originalReturnType instanceof ReflectionIntersectionType) { $returnType = []; foreach ($originalReturnType->getTypes() as $type) { $returnType[] = $type->getName(); } $this->setReturnType(implode($originalReturnType instanceof ReflectionIntersectionType ? '&' : '|', $returnType)); } elseif ($originalReturnType) { throw new LogicException('Unexpected ' . get_class($type)); } } }