Passed
Push — main ( f83e77...eadd2b )
by Dimitri
05:50 queued 01:12
created

Event::isPropagationStopped()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of Blitz PHP framework.
5
 *
6
 * (c) 2022 Dimitri Sitchet Tomkeu <[email protected]>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace BlitzPHP\Event;
13
14
use BlitzPHP\Contracts\Event\EventInterface;
15
16
/**
17
 * Event
18
 *
19
 * @credit      https://www.phpclasses.org/package/9961-PHP-Manage-events-implementing-PSR-14-interface.html - Kiril Savchev <[email protected]>
20
 */
21
class Event implements EventInterface
22
{
23
    /**
24
     * le nom de l'evenement
25
     *
26
     * @var string
27
     */
28
    protected $name = '';
29
30
    /**
31
     * Les paramètres de l'evenement
32
     *
33
     * @var array
34
     */
35
    protected $params = [];
36
37
    /**
38
     * Indicateur indiquant si l'événement doit être arrêté lors du déclenchement
39
     *
40
     * @var bool
41
     */
42
    protected $isPropagationStopped = false;
43
44
    /**
45
     * Creation de l'evenement
46
     *
47
     * @param mixed|null $target La cible de l'evenement
48
     */
49
    public function __construct(?string $name = '', protected $target = null, array $params = [])
50
    {
51 8
        $this->name   = $name;
52 8
        $this->params = $params;
53
    }
54
55
    /**
56
     * {@inheritDoc}
57
     */
58
    public function getName(): string
59
    {
60 8
        return $this->name;
61
    }
62
63
    /**
64
     * {@inheritDoc}
65
     */
66
    public function setName(string $name): void
67
    {
68
        $this->name = $name;
69
    }
70
71
    /**
72
     * {@inheritDoc}
73
     */
74
    public function getParams(): array
75
    {
76
        return $this->params;
77
    }
78
79
    /**
80
     * {@inheritDoc}
81
     */
82
    public function getParam(string $name)
83
    {
84
        return $this->params[$name] ?? null;
85
    }
86
87
    /**
88
     * {@inheritDoc}
89
     */
90
    public function setParams(array $params): void
91
    {
92
        $this->params = $params;
93
    }
94
95
    /**
96
     * {@inheritDoc}
97
     */
98
    public function getTarget()
99
    {
100
        return $this->target;
101
    }
102
103
    /**
104
     * {@inheritDoc}
105
     */
106
    public function setTarget($target): void
107
    {
108
        $this->target = $target;
109
    }
110
111
    /**
112
     * {@inheritDoc}
113
     */
114
    public function isPropagationStopped(): bool
115
    {
116 6
        return $this->isPropagationStopped;
117
    }
118
119
    /**
120
     * {@inheritDoc}
121
     */
122
    public function stopPropagation(bool $flag = true): void
123
    {
124 2
        $this->isPropagationStopped = $flag;
125
    }
126
}
127