Completed
Push — 2.x ( a081e5 )
by Daniel
15:13
created

ProvidesEventsInputFilter   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setEventManager() 0 5 1
B getEventManager() 0 19 7
1
<?php
2
namespace ZfcUser\InputFilter;
3
use Zend\InputFilter\InputFilter;
4
use Zend\EventManager\EventManagerInterface;
5
use Zend\EventManager\EventManager;
6
class ProvidesEventsInputFilter extends InputFilter
7
{
8
    /**
9
     * @var EventManagerInterface
10
     */
11
    protected $events;
12
    /**
13
     * Set the event manager instance used by this context
14
     *
15
     * @param  EventManagerInterface $events
16
     * @return mixed
17
     */
18
    public function setEventManager(EventManagerInterface $events)
19
    {
20
        $this->events = $events;
21
        return $this;
22
    }
23
    /**
24
     * Retrieve the event manager
25
     *
26
     * Lazy-loads an EventManager instance if none registered.
27
     *
28
     * @return EventManagerInterface
29
     */
30
    public function getEventManager()
31
    {
32
        if (!$this->events instanceof EventManagerInterface) {
33
            $identifiers = array(__CLASS__, get_called_class());
34
            if (isset($this->eventIdentifier)) {
35
                if ((is_string($this->eventIdentifier))
36
                    || (is_array($this->eventIdentifier))
37
                    || ($this->eventIdentifier instanceof \Traversable)
38
                ) {
39
                    $identifiers = array_unique($identifiers + (array) $this->eventIdentifier);
40
                } 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...
41
                    $identifiers[] = $this->eventIdentifier;
42
                }
43
                // silently ignore invalid eventIdentifier types
44
            }
45
            $this->setEventManager(new EventManager(null, $identifiers));
46
        }
47
        return $this->events;
48
    }
49
}
50