From ce8dfed825b3adb07c4b728889f4562256bffb55 Mon Sep 17 00:00:00 2001 From: Frank de Jonge Date: Sat, 25 Nov 2023 07:39:58 +0100 Subject: [PATCH] Do not resolve intersection types when doing type inflection for event handler mapping. --- .../InflectHandlerMethodsFromType.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/EventConsumption/InflectHandlerMethodsFromType.php b/src/EventConsumption/InflectHandlerMethodsFromType.php index 4a412c44..214f1454 100644 --- a/src/EventConsumption/InflectHandlerMethodsFromType.php +++ b/src/EventConsumption/InflectHandlerMethodsFromType.php @@ -57,12 +57,18 @@ protected function firstParameterType(ReflectionMethod $method): ?ReflectionType */ protected function acceptedTypes(ReflectionType $type): array { + $acceptedTypes = []; + if ($type instanceof ReflectionNamedType) { - return [$type]; + $acceptedTypes[] = $type; } elseif ($type instanceof ReflectionUnionType) { - return $type->getTypes(); + foreach ($type->getTypes() as $type) { + if ($type instanceof ReflectionNamedType) { + $acceptedTypes[] = $type; + } + } } - return []; + return $acceptedTypes; } }