Event   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 19
dl 0
loc 103
c 0
b 0
f 0
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getSourceClass() 0 2 1
A getSourceObject() 0 2 1
A __construct() 0 5 1
A isPropagatable() 0 2 1
A getPayload() 0 2 1
A getEventName() 0 2 1
A startPropagation() 0 4 1
A stopPropagation() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * @Author : a.zinovyev
6
 * @Package: emittr
7
 * @License: http://www.opensource.org/licenses/mit-license.php
8
 */
9
10
namespace xobotyi\emittr;
11
12
13
/**
14
 * Class Event
15
 *
16
 * @package xobotyi\emittr
17
 */
18
class Event
19
{
20
    /**
21
     * @var string
22
     */
23
    private $eventName;
24
    /**
25
     * @var mixed
26
     */
27
    private $payload;
28
    /**
29
     * @var bool
30
     */
31
    private $propagate = true;
32
    /**
33
     * @var string
34
     */
35
    private $sourceClass;
36
    /**
37
     * @var object
38
     */
39
    private $sourceObject;
40
41
    /**
42
     * Event constructor.
43
     *
44
     * @param string      $evtName
45
     * @param mixed       $payload
46
     * @param string|null $sourceClass
47
     * @param object|null $sourceObject
48
     */
49
    public function __construct(string $evtName, $payload = null, string $sourceClass = null, $sourceObject = null) {
50
        $this->eventName    = $evtName;
51
        $this->payload      = $payload;
52
        $this->sourceClass  = $sourceClass;
53
        $this->sourceObject = $sourceObject;
54
    }
55
56
    /**
57
     * Stop the event propagation.
58
     *
59
     * @return \xobotyi\emittr\Event
60
     */
61
    public function stopPropagation() :self {
62
        $this->propagate = false;
63
64
        return $this;
65
    }
66
67
    /**
68
     * Resume the event propagation
69
     *
70
     * @return \xobotyi\emittr\Event
71
     */
72
    public function startPropagation() :self {
73
        $this->propagate = true;
74
75
        return $this;
76
    }
77
78
    /**
79
     * Check if event is propagatable
80
     *
81
     * @return bool
82
     */
83
    public function isPropagatable() :bool {
84
        return $this->propagate;
85
    }
86
87
    /**
88
     * Return the event name
89
     *
90
     * @return string
91
     */
92
    public function getEventName() :string {
93
        return $this->eventName;
94
    }
95
96
    /**
97
     * Return the event payload
98
     *
99
     * @return mixed|null
100
     */
101
    public function getPayload() {
102
        return $this->payload;
103
    }
104
105
    /**
106
     * Return the object emitted the event
107
     *
108
     * @return object|null
109
     */
110
    public function getSourceObject() {
111
        return $this->sourceObject;
112
    }
113
114
    /**
115
     * Return the name of class emitted the event
116
     *
117
     * @return string|null
118
     */
119
    public function getSourceClass() :?string {
120
        return $this->sourceClass;
121
    }
122
}