Skip to content

Commit

Permalink
fix(kernel): Fix IdeHelper error
Browse files Browse the repository at this point in the history
  • Loading branch information
doyouhaobaby committed Dec 4, 2020
1 parent 4a255b4 commit 853613b
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/Leevel/Kernel/Utils/IdeHelper.php
Expand Up @@ -26,9 +26,8 @@
use ReflectionFunction;
use ReflectionFunctionAbstract;
use ReflectionMethod;
use ReflectionNamedType;
use ReflectionParameter;
use ReflectionType;
use ReflectionUnionType;

/**
* IDE 生成.
Expand Down Expand Up @@ -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;
}

/**
* 整理方法参数.
*/
Expand All @@ -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();
}

Expand Down

0 comments on commit 853613b

Please sign in to comment.