Skip to content

Commit 10d379a

Browse files
[3.4] Fix support for PHP8 union types
1 parent d8e0887 commit 10d379a

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

LazyProxy/ProxyHelper.php

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,36 @@ public static function getTypeHint(\ReflectionFunctionAbstract $r, \ReflectionPa
3939
if (!$type) {
4040
return null;
4141
}
42-
if (!\is_string($type)) {
43-
$name = $type instanceof \ReflectionNamedType ? $type->getName() : $type->__toString();
4442

45-
if ($type->isBuiltin()) {
46-
return $noBuiltin ? null : $name;
43+
$types = [];
44+
45+
foreach ($type instanceof \ReflectionUnionType ? $type->getTypes() : [$type] as $type) {
46+
$name = $type instanceof \ReflectionNamedType ? $type->getName() : (string) $type;
47+
48+
if (!\is_string($type) && $type->isBuiltin()) {
49+
if (!$noBuiltin) {
50+
$types[] = $name;
51+
}
52+
continue;
4753
}
48-
}
49-
$lcName = strtolower($name);
50-
$prefix = $noBuiltin ? '' : '\\';
5154

52-
if ('self' !== $lcName && 'parent' !== $lcName) {
53-
return $prefix.$name;
54-
}
55-
if (!$r instanceof \ReflectionMethod) {
56-
return null;
57-
}
58-
if ('self' === $lcName) {
59-
return $prefix.$r->getDeclaringClass()->name;
55+
$lcName = strtolower($name);
56+
$prefix = $noBuiltin ? '' : '\\';
57+
58+
if ('self' !== $lcName && 'parent' !== $lcName) {
59+
$types[] = '' !== $prefix ? $prefix.$name : $name;
60+
continue;
61+
}
62+
if (!$r instanceof \ReflectionMethod) {
63+
continue;
64+
}
65+
if ('self' === $lcName) {
66+
$types[] = $prefix.$r->getDeclaringClass()->name;
67+
} else {
68+
$types[] = ($parent = $r->getDeclaringClass()->getParentClass()) ? $prefix.$parent->name : null;
69+
}
6070
}
6171

62-
return ($parent = $r->getDeclaringClass()->getParentClass()) ? $prefix.$parent->name : null;
72+
return $types ? implode('|', $types) : null;
6373
}
6474
}

0 commit comments

Comments
 (0)