Completed
Push — master ( 40a577...55d540 )
by n
02:35
created

Event   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 111
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 94.12%

Importance

Changes 0
Metric Value
wmc 13
lcom 2
cbo 0
dl 0
loc 111
ccs 32
cts 34
cp 0.9412
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getName() 0 4 1
A getTarget() 0 4 1
A getParams() 0 4 1
A getParam() 0 8 2
A setTarget() 0 4 1
A setParams() 0 4 1
A isPropagationStopped() 0 4 1
A setName() 0 8 2
A stopPropagation() 0 8 2
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 24
    public function __construct(string $name, $target = null, array $params = [])
26
    {
27 24
        $this->name = $name;
28 24
        $this->target = $target;
29 24
        $this->params = $params;
30 24
        $this->isPropagationStopped = false;
31 24
    }
32
33
    /**
34
     * @inheritdoc
35
     */
36 11
    public function getName(): string
37
    {
38 11
        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(): array
53
    {
54 3
        return $this->params;
55
    }
56
57
    /**
58
     * @inheritdoc
59
     */
60 3
    public function getParam(string $name)
61
    {
62 3
        if (!isset($this->params[$name])) {
63 1
            return null;
64
        }
65
66 3
        return $this->params[$name];
67
    }
68
69
    /**
70
     * @inheritdoc
71
     */
72 1
    public function setName(string $name)
73
    {
74 1
        if (!is_string($name)) {
75
            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(bool $flag)
101
    {
102 2
        if (!is_bool($flag)) {
103
            throw new \InvalidArgumentException('$flag must be a bool.');
104
        }
105
106 2
        $this->isPropagationStopped = $flag;
107 2
    }
108
109
    /**
110
     * @inheritdoc
111
     */
112 8
    public function isPropagationStopped(): bool
113
    {
114 8
        return $this->isPropagationStopped;
115
    }
116
}
117