EntityEventManager   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A trigger() 0 4 1
A attach() 0 4 1
A createEvent() 0 4 1
1
<?php
2
3
namespace T4web\DomainModule;
4
5
use Zend\EventManager\EventManager;
6
use T4webDomainInterface\EventManagerInterface;
7
use T4webDomainInterface\EventInterface;
8
use T4webDomainInterface\EntityInterface;
9
10
class EntityEventManager implements EventManagerInterface
11
{
12
    /**
13
     * @var EventManager
14
     */
15
    private $eventManager;
16
17
    /**
18
     * EntityEventManager constructor.
19
     * @param EventManager $eventManager
20
     */
21
    public function __construct(EventManager $eventManager)
22
    {
23
        $this->eventManager = $eventManager;
24
    }
25
26
    /**
27
     * @param EventInterface $event
28
     */
29
    public function trigger(EventInterface $event)
30
    {
31
        $this->eventManager->triggerEvent($event);
0 ignored issues
show
Documentation introduced by
$event is of type object<T4webDomainInterface\EventInterface>, but the function expects a object<Zend\EventManager\EventInterface>.

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...
32
    }
33
34
    /**
35
     * @param $event
36
     * @param $listener
37
     */
38
    public function attach($event, $listener = null)
39
    {
40
        $this->eventManager->attach($event, $listener);
0 ignored issues
show
Documentation introduced by
$listener is of type null, 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...
41
    }
42
43
    /**
44
     * @param $event
45
     * @param EntityInterface|null $entity
46
     * @param array $data
47
     * @return EntityEvent
48
     */
49
    public function createEvent($event, EntityInterface $entity = null, array $data = [])
50
    {
51
        return new EntityEvent($event, $entity, $data);
52
    }
53
}
54