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

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