Completed
Push — 11.0.x ( e73ee6...d04824 )
by Tom
29s queued 23s
created

EventDispatcher   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 20
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A subscribeTo() 0 3 1
A dispatch() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ApiSkeletons\Doctrine\ORM\GraphQL\Event;
6
7
use League\Event\Emitter as EventDispatcherClass;
8
9
/**
10
 * This class is a wrapper for the League\Event\Emitter class.
11
 * Because the version of League\Event was changed from 3.0 to 2.2,
12
 * this class was created to keep the code consistent and move easily
13
 * move back to 3.0 when the time comes.
14
 */
15
class EventDispatcher
16
{
17
    public function __construct(
18
        protected EventDispatcherClass $eventDispatcher,
19
    ) {
20
    }
21
22
    /**
23
     * Emit an event
24
     *
25
     * @psalm-suppress TooManyArguments
26
     */
27
    public function dispatch(string $event, mixed $payload = null): void
28
    {
29
        $this->eventDispatcher->emit($event, $payload);
30
    }
31
32
    public function subscribeTo(string $event, callable $listener): void
33
    {
34
        $this->eventDispatcher->addListener($event, $listener);
35
    }
36
}
37