Event   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 101
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setAction() 0 5 1
A setOccurredAt() 0 5 1
A setEmail() 0 5 1
A addProperty() 0 5 1
A toDrip() 0 5 1
A removeProperty() 0 7 2
A setProperties() 0 5 1
1
<?php
2
3
namespace Glorand\Drip\Models;
4
5
use DateTime;
6
use Glorand\Drip\Models\Traits\Jsonable;
7
use JsonSerializable;
8
9
class Event implements JsonSerializable
10
{
11
    use Jsonable;
12
13
    /**
14
     * @var array
15
     */
16
    protected $properties;
17
    /**
18
     * @var string
19
     */
20
    protected $email;
21
    /**
22
     * @var string
23
     */
24
    protected $action;
25
    /**
26
     * @var DateTime
27
     */
28
    protected $occurred_at;
29
30
    /**
31
     * @param string $key
32
     * @param string $value
33
     *
34
     * @return Event
35
     */
36 2
    public function addProperty(string $key, string $value): self
37
    {
38 2
        $this->properties[$key] = $value;
39
40 2
        return $this;
41
    }
42
43
    /**
44
     * @param string $key
45
     *
46
     * @return Event
47
     */
48 1
    public function removeProperty(string $key): self
49
    {
50 1
        if (!empty($this->properties[$key])) {
51 1
            unset($this->properties[$key]);
52
        }
53
54 1
        return $this;
55
    }
56
57
    /**
58
     * @param array $properties
59
     *
60
     * @return Event
61
     */
62 1
    public function setProperties(array $properties): self
63
    {
64 1
        $this->properties = $properties;
65
66 1
        return $this;
67
    }
68
69
    /**
70
     * @param string $email
71
     *
72
     * @return Event
73
     */
74 3
    public function setEmail(string $email): self
75
    {
76 3
        $this->email = $email;
77
78 3
        return $this;
79
    }
80
81
    /**
82
     * @param string $action
83
     *
84
     * @return Event
85
     */
86 3
    public function setAction(string $action): self
87
    {
88 3
        $this->action = $action;
89
90 3
        return $this;
91
    }
92
93
    /**
94
     * @param DateTime $occurredAt
95
     *
96
     * @return Event
97
     */
98 2
    public function setOccurredAt(DateTime $occurredAt): self
99
    {
100 2
        $this->occurred_at = $occurredAt;
101
102 2
        return $this;
103
    }
104
105 2
    public function toDrip(): array
106
    {
107
        return [
108
            "events" => [
109 2
                $this->jsonSerialize(),
110
            ],
111
        ];
112
    }
113
}
114