ListenerTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 31
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A eventsListening() 0 4 1
A registerEvent() 0 9 2
1
<?php
2
/**
3
 * Phossa Project
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  Library
8
 * @package   Phossa2\Event
9
 * @copyright Copyright (c) 2016 phossa.com
10
 * @license   http://mit-license.org/ MIT License
11
 * @link      http://www.phossa.com/
12
 */
13
/*# declare(strict_types=1); */
14
15
namespace Phossa2\Event\Traits;
16
17
use Phossa2\Event\Interfaces\ListenerInterface;
18
19
/**
20
 * ListenerTrait
21
 *
22
 * @package Phossa2\Event
23
 * @author  Hong Zhang <[email protected]>
24
 * @see     ListenerInterface
25
 * @version 2.1.4
26
 * @since   2.1.3 added
27
 * @since   2.1.4 updated
28
 */
29
trait ListenerTrait
30
{
31
    /**
32
     * Events listening
33
     *
34
     * @var    array
35
     * @access protected
36
     */
37
    protected $events_listening = [];
38
39
    /**
40
     * {@inheritDoc}
41
     */
42
    public function eventsListening()/*# : array */
43
    {
44
        return $this->events_listening;
45
    }
46
47
    /**
48
     * {@inheritDoc}
49
     */
50
    public function registerEvent(/*# string */ $eventName, $handler)
51
    {
52
        if (!isset($this->events_listening[$eventName])) {
53
            $this->events_listening[$eventName] = [];
54
        }
55
        $this->events_listening[$eventName][] = $handler;
56
57
        return $this;
58
    }
59
}
60