• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

68publishers / event-dispatcher-extra / 15322966619

29 May 2025 11:35AM UTC coverage: 83.824%. First build
15322966619

Pull #1

github

web-flow
Merge f84369011 into 858a38b40
Pull Request #1: PHP 8.4 support + checks

57 of 68 new or added lines in 4 files covered. (83.82%)

57 of 68 relevant lines covered (83.82%)

0.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.88
/src/ComposedEventDispatcher.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace SixtyEightPublishers\EventDispatcherExtra;
6

7
use Symfony\Component\EventDispatcher\EventDispatcher;
8
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
9
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
10

11
final readonly class ComposedEventDispatcher implements EventDispatcherInterface
12
{
13
    public function __construct(
1✔
14
        private EventDispatcherInterface $globalEventDispatcher,
15
        private EventDispatcherInterface $localEventDispatcher = new EventDispatcher(),
16
    ) {
17
    }
1✔
18

19
    public function addListener(string $eventName, callable $listener, int $priority = 0): void
20
    {
21
        $this->localEventDispatcher->addListener(
1✔
22
            eventName: $eventName,
1✔
23
            listener: $listener,
24
            priority: $priority,
25
        );
26
    }
1✔
27

28
    public function addSubscriber(EventSubscriberInterface $subscriber): void
29
    {
30
        $this->localEventDispatcher->addSubscriber(
1✔
31
            subscriber: $subscriber,
1✔
32
        );
33
    }
1✔
34

35
    public function removeListener(string $eventName, callable $listener): void
36
    {
37
        $this->localEventDispatcher->removeListener(
1✔
38
            eventName: $eventName,
1✔
39
            listener: $listener,
40
        );
41
    }
1✔
42

43
    public function removeSubscriber(EventSubscriberInterface $subscriber): void
44
    {
45
        $this->localEventDispatcher->removeSubscriber(
1✔
46
            subscriber: $subscriber,
1✔
47
        );
48
    }
1✔
49

50
    public function getListeners(?string $eventName = null): array
51
    {
52
        /** @var ($eventName is null ? array<string, list<callable>> : list<callable>) $global */
53
        $global = $this->globalEventDispatcher->getListeners(eventName: $eventName);
1✔
54
        /** @var ($eventName is null ? array<string, list<callable>> : list<callable>) $local */
55
        $local = $this->localEventDispatcher->getListeners(eventName: $eventName);
1✔
56

57
        if (null !== $eventName) {
1✔
58
            return array_merge($global, $local);
1✔
59
        }
60

61
        /**
62
         * @var string         $name
63
         * @var list<callable> $events
64
         */
65
        foreach ($global as $name => $events) {
1✔
66
            if (isset($local[$name])) {
1✔
67
                /** @var list<callable> $localEvents */
68
                $localEvents = $local[$name];
1✔
69
                $global[$name] = array_merge($events, $localEvents);
1✔
70
            }
71
        }
72

73
        return $global;
1✔
74
    }
75

76
    public function getListenerPriority(string $eventName, callable $listener): ?int
77
    {
NEW
78
        return $this->globalEventDispatcher->getListenerPriority(
×
NEW
79
            eventName: $eventName,
×
80
            listener: $listener,
NEW
81
        ) ?? $this->localEventDispatcher->getListenerPriority(
×
NEW
82
            eventName: $eventName,
×
83
            listener: $listener,
84
        );
85
    }
86

87
    public function hasListeners(?string $eventName = null): bool
88
    {
89
        return $this->globalEventDispatcher->hasListeners(eventName: $eventName) || $this->localEventDispatcher->hasListeners(eventName: $eventName);
1✔
90
    }
91

92
    public function dispatch(object $event, ?string $eventName = null): object
93
    {
94
        $this->globalEventDispatcher->dispatch(
1✔
95
            event: $event,
1✔
96
            eventName: $eventName,
97
        );
98
        $this->localEventDispatcher->dispatch(
1✔
99
            event: $event,
1✔
100
            eventName: $eventName,
101
        );
102

103
        return $event;
1✔
104
    }
105
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc