Completed
Push — master ( ae6a92...7b43ed )
by Frank
01:13
created

src/BufferedEventDispatcher.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
declare(strict_types=1);
4
5
namespace League\Event;
6
7
use Psr\EventDispatcher\EventDispatcherInterface;
8
9
class BufferedEventDispatcher implements EventDispatcherInterface, ListenerAcceptor
10
{
11
    use EventGeneratorBehavior {
12
        recordEvent as protected;
13
        releaseEvents as protected;
14
    }
15
16
    /**
17
     * @var EventDispatcherInterface
18
     */
19
    private $dispatcher;
20
21
    public function __construct(EventDispatcherInterface $dispatcher)
22
    {
23
        $this->dispatcher = $dispatcher;
24
    }
25
26
    public function dispatch(object $event): void
27
    {
28
        $this->recordEvent($event);
29
    }
30
31
    public function dispatchBufferedEvents(): void
32
    {
33
        foreach ($this->releaseEvents() as $event) {
34
            $this->dispatcher->dispatch($event);
35
        }
36
    }
37
38 View Code Duplication
    public function subscribeTo(string $event, callable $listener, int $priority = ListenerPriority::NORMAL): void
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
    {
40
        if ( ! $this->dispatcher instanceof ListenerAcceptor) {
41
            throw UnableToSubscribeListener::becauseTheEventDispatcherDoesNotAcceptListeners($this->dispatcher);
42
        }
43
44
        $this->dispatcher->subscribeTo($event, $listener, $priority);
45
    }
46
47 View Code Duplication
    public function subscribeOnceTo(string $event, callable $listener, int $priority = ListenerPriority::NORMAL): void
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
    {
49
        if ( ! $this->dispatcher instanceof ListenerAcceptor) {
50
            throw UnableToSubscribeListener::becauseTheEventDispatcherDoesNotAcceptListeners($this->dispatcher);
51
        }
52
53
        $this->dispatcher->subscribeOnceTo($event, $listener, $priority);
54
    }
55
56
    public function subscribeListenersFrom(ListenerSubscriber $subscriber): void
57
    {
58
        if ( ! $this->dispatcher instanceof ListenerAcceptor) {
59
            throw UnableToSubscribeListener::becauseTheEventDispatcherDoesNotAcceptListeners($this->dispatcher);
60
        }
61
62
        $this->dispatcher->subscribeListenersFrom($subscriber);
63
    }
64
}
65