Completed
Push — master ( 809d1b...4afa81 )
by n
01:51
created

Event::getParams()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace N1215\Tsukuyomi\Event;
5
6
class Event implements EventInterface
7
{
8
    /** @var string  */
9
    private $name;
10
11
    /** @var string|object|null */
12
    private $target;
13
14
    /** @var array  */
15
    private $params;
16
17
    /** @var bool  */
18
    private $isPropagationStopped;
19
20
    /**
21
     * @param string $name
22
     * @param string|object|null $target
23
     * @param array $params
24
     */
25 15
    public function __construct(string $name, $target = null, array $params = [])
26
    {
27 15
        $this->name = $name;
28 15
        $this->target = $target;
29 15
        $this->params = $params;
30 15
        $this->isPropagationStopped = false;
31 15
    }
32
33
    /**
34
     * @inheritdoc
35
     */
36 3
    public function getName()
37
    {
38 3
        return $this->name;
39
    }
40
41
    /**
42
     * @inheritdoc
43
     */
44 3
    public function getTarget()
45
    {
46 3
        return $this->target;
47
    }
48
49
    /**
50
     * @inheritdoc
51
     */
52 3
    public function getParams()
53
    {
54 3
        return $this->params;
55
    }
56
57
    /**
58
     * @inheritdoc
59
     */
60 2
    public function getParam($name)
61
    {
62 2
        if (!isset($this->params[$name])) {
63 1
            return null;
64
        }
65
66 2
        return $this->params[$name];
67
    }
68
69
    /**
70
     * @inheritdoc
71
     */
72 2
    public function setName($name)
73
    {
74 2
        if (!is_string($name)) {
75 1
            throw new \InvalidArgumentException('$name must be a string.');
76
        }
77
78 1
        $this->name = $name;
79 1
    }
80
81
    /**
82
     * @inheritdoc
83
     */
84 1
    public function setTarget($target)
85
    {
86 1
        $this->target = $target;
87 1
    }
88
89
    /**
90
     * @inheritdoc
91
     */
92 1
    public function setParams(array $params)
93
    {
94 1
        $this->params = $params;
95 1
    }
96
97
    /**
98
     * @inheritdoc
99
     */
100 2
    public function stopPropagation($flag)
101
    {
102 2
        if (!is_bool($flag)) {
103 1
            throw new \InvalidArgumentException('$flag must be a bool.');
104
        }
105
106 1
        $this->isPropagationStopped = $flag;
107 1
    }
108
109
    /**
110
     * @inheritdoc
111
     */
112 2
    public function isPropagationStopped()
113
    {
114 2
        return $this->isPropagationStopped;
115
    }
116
}
117