From 853613be156c36618c4fe626f61ef30eff4609dc Mon Sep 17 00:00:00 2001 From: XiangMin Liu <635750556@qq.com> Date: Sat, 5 Dec 2020 01:29:37 +0800 Subject: [PATCH] fix(kernel): Fix IdeHelper error --- src/Leevel/Kernel/Utils/IdeHelper.php | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/Leevel/Kernel/Utils/IdeHelper.php b/src/Leevel/Kernel/Utils/IdeHelper.php index 6932ce57b..f1c4a5dea 100644 --- a/src/Leevel/Kernel/Utils/IdeHelper.php +++ b/src/Leevel/Kernel/Utils/IdeHelper.php @@ -26,9 +26,8 @@ use ReflectionFunction; use ReflectionFunctionAbstract; use ReflectionMethod; -use ReflectionNamedType; use ReflectionParameter; -use ReflectionType; +use ReflectionUnionType; /** * IDE 生成. @@ -159,21 +158,15 @@ protected function getReflectorReturnType(ReflectionFunctionAbstract $reflector) return ''; } - $returnType = $this->convertReflectionNamedType($returnType); + if ($returnType instanceof ReflectionUnionType) { + return (string) $returnType; + } - return ($returnType->allowsNull() ? '?' : ''). + return ($returnType->allowsNull() && 'mixed' !== $returnType->getName() ? '?' : ''). (!$returnType->isBuiltin() ? '\\' : ''). $returnType->getName(); } - /** - * 转换为 \ReflectionNamedType. - */ - protected function convertReflectionNamedType(ReflectionType $reflectionType): ReflectionNamedType - { - return $reflectionType; - } - /** * 整理方法参数. */ @@ -184,7 +177,9 @@ protected function normalizeParam(ReflectionParameter $param, bool $onlyReturnNa } $paramClassName = null; - if (($reflectionType = $param->getType()) && false === $reflectionType->isBuiltin()) { + if (($reflectionType = $param->getType()) && + !($reflectionType instanceof ReflectionUnionType) && + false === $reflectionType->isBuiltin()) { $paramClassName = $reflectionType->getName(); }