LeagueEventPublisher   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 53
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A publishEventsFrom() 0 5 1
A publish() 0 4 1
A addListener() 0 7 1
1
<?php
2
3
/**
4
 * This file is part of slick/cqrs-tools
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\CQRSTools\Infrastructure\Events;
11
12
use League\Event\EmitterInterface;
13
use Slick\CQRSTools\Event;
14
use Slick\CQRSTools\Event\EventGenerator;
15
use Slick\CQRSTools\Event\EventListener;
16
use Slick\CQRSTools\Event\EventPublisher;
17
18
/**
19
 * LeagueEventPublisher
20
 *
21
 * @package Slick\CQRSTools\Infrastructure\Events
22
*/
23
final class LeagueEventPublisher implements EventPublisher
24
{
25
    /**
26
     * @var EmitterInterface
27
     */
28
    private $emitter;
29
30
    /**
31
     * Creates a  League Event Publisher
32
     *
33
     * @param EmitterInterface $emitter
34
     */
35
    public function __construct(EmitterInterface $emitter)
36
    {
37
        $this->emitter = $emitter;
38
    }
39
40
    /**
41
     * Publishes all event generated by provided generator
42
     *
43
     * @param EventGenerator $generator
44
     */
45
    public function publishEventsFrom(EventGenerator $generator): void
46
    {
47
        $events = $generator->releaseEvents();
48
        $this->emitter->emitBatch($events);
49
    }
50
51
    /**
52
     * Publishes a single event
53
     *
54
     * @param Event $event
55
     */
56
    public function publish(Event $event): void
57
    {
58
        $this->emitter->emit($event);
59
    }
60
61
    /**
62
     * Adds an event listener
63
     *
64
     * @param string        $event
65
     * @param EventListener $listener
66
     * @param int           $priority
67
     */
68
    public function addListener(
69
        string $event,
70
        EventListener $listener,
71
        int $priority = EmitterInterface::P_NORMAL
72
    ): void {
73
        $this->emitter->addListener($event, $listener, $priority);
0 ignored issues
show
Documentation introduced by
$listener is of type object<Slick\CQRSTools\Event\EventListener>, but the function expects a callable.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
74
    }
75
}
76