Passed
Push — master ( 444157...9a79fb )
by Michał
05:59
created

Event::getLaunchCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Event Object Class
5
 *
6
 * @package     BlueEvent
7
 * @author      Michał Adamiak    <[email protected]>
8
 * @copyright   chajr/bluetree
9
 */
10
11
declare(strict_types=1);
12
13
namespace BlueEvent\Event\Base;
14
15
use BlueEvent\Event\Base\Interfaces\EventInterface;
16
17
abstract class Event implements EventInterface
18
{
19
    /**
20
     * store information how many times event object was called
21
     *
22
     * @var int
23
     */
24
    protected static $launchCount = 0;
25
26
    /**
27
     * store information that event propagation is stopped or not
28
     *
29
     * @var bool
30
     */
31
    protected $propagationStopped = false;
32
33
    /**
34
     * @var array
35
     */
36
    protected $eventParameters = [];
37
38
    /**
39
     * @var string
40
     */
41
    protected $eventName = '';
42
43
    /**
44
     * create event instance
45
     *
46
     * @param string $eventName
47
     * @param array $parameters
48
     */
49 13
    public function __construct(string $eventName, array $parameters)
50
    {
51 13
        $this->eventName = $eventName;
52 13
        $this->eventParameters = $parameters;
53
54 13
        self::$launchCount++;
55 13
    }
56
57
    /**
58
     * return number how many times event was called
59
     *
60
     * @return int
61
     */
62 2
    public static function getLaunchCount(): int
63
    {
64 2
        return self::$launchCount;
65
    }
66
67
    /**
68
     * return information that event propagation is stopped or not
69
     *
70
     * @return bool
71
     */
72 13
    public function isPropagationStopped(): bool
73
    {
74 13
        return $this->propagationStopped;
75
    }
76
77
    /**
78
     * allow to stop event propagation
79
     *
80
     * @return $this
81
     */
82 1
    public function stopPropagation(): self
83
    {
84 1
        $this->propagationStopped = true;
85 1
        return $this;
86
    }
87
88
    /**
89
     * @return string
90
     */
91 1
    public function getEventCode(): string
92
    {
93 1
        return $this->eventName;
94
    }
95
96
    /**
97
     * @return array
98
     */
99 5
    public function getEventParameters(): array
100
    {
101 5
        return $this->eventParameters;
102
    }
103
}
104