mirror of
https://github.com/pestphp/pest.git
synced 2026-03-12 02:37:22 +01:00
feat: handle unions (PHP 8)
This commit is contained in:
@ -12,6 +12,7 @@ use ReflectionException;
|
|||||||
use ReflectionFunction;
|
use ReflectionFunction;
|
||||||
use ReflectionNamedType;
|
use ReflectionNamedType;
|
||||||
use ReflectionParameter;
|
use ReflectionParameter;
|
||||||
|
use ReflectionUnionType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
@ -165,9 +166,23 @@ final class Reflection
|
|||||||
$arguments = [];
|
$arguments = [];
|
||||||
|
|
||||||
foreach ($parameters as $parameter) {
|
foreach ($parameters as $parameter) {
|
||||||
/** @var ReflectionNamedType|null $type */
|
/** @var ReflectionNamedType|ReflectionUnionType|null $types */
|
||||||
$type = ($parameter->hasType()) ? $parameter->getType() : null;
|
$types = ($parameter->hasType()) ? $parameter->getType() : null;
|
||||||
$arguments[$parameter->getName()] = (is_null($type)) ? 'mixed' : $type->getName();
|
|
||||||
|
if (is_null($types)) {
|
||||||
|
$arguments[$parameter->getName()] = 'mixed';
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$arguments[$parameter->getName()] = implode('|', array_map(
|
||||||
|
static function (ReflectionNamedType $type): string {
|
||||||
|
return $type->getName();
|
||||||
|
},
|
||||||
|
($types instanceof ReflectionNamedType)
|
||||||
|
? [$types] // NOTE: normalize as list of to handle unions
|
||||||
|
: $types->getTypes(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $arguments;
|
return $arguments;
|
||||||
|
|||||||
Reference in New Issue
Block a user