Passed
Pull Request — master (#17)
by Alex
08:09
created

ListenerConfig::getListener()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Arp\EventDispatcher\Listener;
6
7
/**
8
 * @author  Alex Patterson <[email protected]>
9
 * @package Arp\EventDispatcher\Listener
10
 */
11
class ListenerConfig
12
{
13
    /**
14
     * @var callable
15
     */
16
    protected $listener;
17
18
    /**
19
     * @var string
20
     */
21
    protected $eventName;
22
23
    /**
24
     * @var int
25
     */
26
    protected $priority;
27
28
    /**
29
     * @param callable $listener
30
     * @param string   $eventName
31
     * @param int      $priority
32
     */
33
    public function __construct(callable $listener, string $eventName, int $priority = 1)
34
    {
35
        $this->setListener($listener);
36
        $this->setEventName($eventName);
37
    }
38
39
    /**
40
     * @return callable
41
     */
42
    public function getListener(): callable
43
    {
44
        return $this->listener;
45
    }
46
47
    /**
48
     * @param callable $listener
49
     */
50
    public function setListener(callable $listener): void
51
    {
52
        $this->listener = $listener;
53
    }
54
55
    /**
56
     * @return string
57
     */
58
    public function getEventName(): string
59
    {
60
        return $this->eventName;
61
    }
62
63
    /**
64
     * @param string $eventName
65
     */
66
    public function setEventName(string $eventName): void
67
    {
68
        $this->eventName = $eventName;
69
    }
70
71
    /**
72
     * @return int
73
     */
74
    public function getPriority(): int
75
    {
76
        return $this->priority;
77
    }
78
79
    /**
80
     * @param int $priority
81
     */
82
    public function setPriority(int $priority): void
83
    {
84
        $this->priority = $priority;
85
    }
86
87
    /**
88
     * @param array $data
89
     */
90
    public function fromArray(array $data): void
91
    {
92
        if (isset($data['listener'])) {
93
            $this->setListener($data['listener']);
94
        }
95
96
        if (isset($data['event_name'])) {
97
            $this->setEventName($data['event_name']);
98
        }
99
100
        if (isset($data['priority'])) {
101
            $this->setPriority($data['priority']);
102
        }
103
    }
104
105
    /**
106
     * @return array
107
     */
108
    public function toArray(): array
109
    {
110
        return [
111
            'listener' => $this->listener,
112
            'event_name' => $this->eventName,
113
            'priority' => $this->priority,
114
        ];
115
    }
116
}
117