Total Complexity | 10 |
Total Lines | 52 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | class Event |
||
8 | { |
||
9 | private $name; |
||
10 | private $timestamp; |
||
11 | private $attributes = []; |
||
12 | |||
13 | 3 | public function __construct(string $name, array $attributes = [], $timestamp = null) |
|
14 | { |
||
15 | 3 | if (is_null($timestamp)) { |
|
16 | 3 | $timestamp = microtime(true); |
|
17 | } |
||
18 | 3 | $this->name = $name; |
|
19 | 3 | $this->timestamp = $timestamp; |
|
20 | 3 | $this->setAttributes($attributes); |
|
21 | 3 | } |
|
22 | |||
23 | 2 | public function getAttribute(string $key) |
|
24 | { |
||
25 | 2 | if (!array_key_exists($key, $this->attributes)) { |
|
26 | 1 | return null; |
|
27 | } |
||
28 | 2 | return $this->attributes[$key]; |
|
29 | } |
||
30 | |||
31 | 3 | public function setAttribute(string $key, $value) : self |
|
32 | { |
||
33 | 3 | $this->attributes[$key] = $value; |
|
34 | 3 | return $this; |
|
35 | } |
||
36 | |||
37 | 1 | public function getAttributes() : array |
|
38 | { |
||
39 | 1 | return $this->attributes; |
|
40 | } |
||
41 | |||
42 | 3 | public function setAttributes(array $attributes) : self |
|
43 | { |
||
44 | 3 | $this->attributes = []; |
|
45 | 3 | foreach ($attributes as $k => $v) { |
|
46 | 3 | $this->setAttribute($k, $v); |
|
47 | } |
||
48 | 3 | return $this; |
|
49 | } |
||
50 | |||
51 | 3 | public function getName() : string |
|
54 | } |
||
55 | |||
56 | 1 | public function getTimestamp() : float |
|
57 | { |
||
58 | 1 | return $this->timestamp; |
|
59 | } |
||
60 | } |