Repository: symfony/symfony
File: src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php (PHP)

Code before:
     * @return string[]
     */
    private function getEventFromTypeDeclaration(ContainerBuilder $container, string $id, string $method): array
    {
        $exception = fn ($id) => new InvalidArgumentException(\sprintf('Service "%s" must define the "event" attribute on "kernel.event_listener" tags.', $id));

        if (
            null === ($class = $container->getDefinition($id)->getClass())
            || !($r = $container->getReflectionClass($class, false))
            || !$r->hasMethod($method)
            || 1 > ($m = $r->getMethod($method))->getNumberOfParameters()
            || !(($type = $m->getParameters()[0]->getType()) instanceof \ReflectionNamedType || $type instanceof \ReflectionUnionType)
        ) {
            throw $exception($id);
        }

        $types = $type instanceof \ReflectionUnionType ? $type->getTypes() : [$type];

        $names = [];
        foreach ($types as $type) {
            if (
                !$type instanceof \ReflectionNamedType
                || $type->isBuiltin()
                || Event::class === ($name = $type->getName()
                )
            ) {
                continue;
            }

            $names[] = $name;
        }

        if (!$names) {
            throw $exception($id);
        }

        return $names;
    }
}

/**
 * @internal
 */
class ExtractingEventDispatcher extends EventDispatcher implements EventSubscriberInterface
{
    public array $listeners = [];

    public static array $aliases = [];
    public static string $subscriber;

    public function addListener(string $eventName, callable|array $listener, int $priority = 0): void

Review comment (suggestion):
```suggestion
            if (!$type instanceof \ReflectionNamedType
                || $type->isBuiltin()
                || Event::class === ($name = $type->getName())
            ) {
```

Code after:
     * @return string[]
     */
    private function getEventFromTypeDeclaration(ContainerBuilder $container, string $id, string $method): array
    {
        if (
            null === ($class = $container->getDefinition($id)->getClass())
            || !($r = $container->getReflectionClass($class, false))
            || !$r->hasMethod($method)
            || 1 > ($m = $r->getMethod($method))->getNumberOfParameters()
            || !(($type = $m->getParameters()[0]->getType()) instanceof \ReflectionNamedType || $type instanceof \ReflectionUnionType)
        ) {
            throw new InvalidArgumentException(\sprintf('Service "%s" must define the "event" attribute on "kernel.event_listener" tags.', $id));
        }

        $types = $type instanceof \ReflectionUnionType ? $type->getTypes() : [$type];

        $names = [];
        foreach ($types as $type) {
            if (!$type instanceof \ReflectionNamedType
                || $type->isBuiltin()
                || Event::class === ($name = $type->getName())
            ) {
                continue;
            }

            $names[] = $name;
        }

        if (!$names) {
            throw new InvalidArgumentException(\sprintf('Service "%s" must define the "event" attribute on "kernel.event_listener" tags.', $id));
        }

        return $names;
    }
}

/**
 * @internal
 */
class ExtractingEventDispatcher extends EventDispatcher implements EventSubscriberInterface
{
    public array $listeners = [];

    public static array $aliases = [];
    public static string $subscriber;

    public function addListener(string $eventName, callable|array $listener, int $priority = 0): void
    {
        $this->listeners[] = [$eventName, $listener[1], $priority];
    }