EventProvider   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setEventManager() 0 18 6
A getEventManager() 0 7 2
1
<?php
2
namespace LmcUser\EventManager;
3
4
use Traversable;
5
use Laminas\EventManager\EventManagerAwareInterface;
6
use Laminas\EventManager\EventManagerInterface;
7
use Laminas\EventManager\EventManager;
8
use Laminas\EventManager\SharedEventManager;
9
10
abstract class EventProvider implements EventManagerAwareInterface
11
{
12
    /**
13
     * @var EventManagerInterface
14
     */
15
    protected $events;
16
    /**
17
     * Set the event manager instance used by this context
18
     *
19
     * @param  EventManagerInterface $events
20
     * @return mixed
21
     */
22
    public function setEventManager(EventManagerInterface $events)
23
    {
24
        $identifiers = array(__CLASS__, get_called_class());
25
        if (isset($this->eventIdentifier)) {
26
            if ((is_string($this->eventIdentifier))
27
                || (is_array($this->eventIdentifier))
28
                || ($this->eventIdentifier instanceof Traversable)
29
            ) {
30
                $identifiers = array_unique(array_merge($identifiers, (array) $this->eventIdentifier));
31
            } elseif (is_object($this->eventIdentifier)) {
0 ignored issues
show
Bug introduced by
The property eventIdentifier does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
32
                $identifiers[] = $this->eventIdentifier;
33
            }
34
            // silently ignore invalid eventIdentifier types
35
        }
36
        $events->setIdentifiers($identifiers);
37
        $this->events = $events;
38
        return $this;
39
    }
40
    /**
41
     * Retrieve the event manager
42
     *
43
     * Lazy-loads an EventManager instance if none registered.
44
     *
45
     * @return EventManagerInterface
46
     */
47
    public function getEventManager()
48
    {
49
        if (!$this->events instanceof EventManagerInterface) {
50
            $this->setEventManager(new EventManager());
51
        }
52
        return $this->events;
53
    }
54
}
55