Completed
Push — master ( 290f71...5c7d58 )
by Tobias
01:52
created

Event   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 18.18%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 1
dl 0
loc 113
ccs 6
cts 33
cp 0.1818
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getCreatedAt() 0 4 1
A setCreatedAt() 0 7 1
A getType() 0 4 1
A setType() 0 7 1
A getDate() 0 4 1
A setDate() 0 7 1
A toArray() 0 15 4
A createFromArray() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Billogram\Model\Invoice;
6
7
use Billogram\Model\CreatableFromArray;
8
9
/**
10
 * @author Ibrahim Hizeoui <[email protected]>
11
 */
12
class Event implements CreatableFromArray
13
{
14
    /**
15
     * @var \DateTime
16
     */
17
    private $createdAt;
18
19
    /**
20
     * @var string
21
     */
22
    private $type;
23
24
    /**
25
     * @var EventData
26
     */
27
    private $data;
28
29
    /**
30
     * @return \DateTime
31
     */
32
    public function getCreatedAt(): \DateTime
33
    {
34
        return $this->createdAt;
35
    }
36
37
    /**
38
     * @param \DateTime $createdAt
39
     *
40
     * @return Event
41
     */
42
    public function setCreatedAt(\DateTime $createdAt)
43
    {
44
        $new = clone $this;
45
        $new->createdAt = $createdAt;
46
47
        return $new;
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    public function getType(): string
54
    {
55
        return $this->type;
56
    }
57
58
    /**
59
     * @param string $type
60
     *
61
     * @return Event
62
     */
63
    public function setType(string $type)
64
    {
65
        $new = clone $this;
66
        $new->type = $type;
67
68
        return $new;
69
    }
70
71
    /**
72
     * @return EventData
73
     */
74
    public function getDate()
75
    {
76
        return $this->data;
77
    }
78
79
    /**
80
     * @param EventData $data
81
     *
82
     * @return Event
83
     */
84
    public function setDate(EventData $data)
85
    {
86
        $new = clone $this;
87
        $new->data = $data;
88
89
        return $new;
90
    }
91
92
    public function toArray()
93
    {
94
        $data = [];
95
        if ($this->createdAt !== null) {
96
            $data['created_at'] = $this->createdAt;
97
        }
98
        if ($this->type !== null) {
99
            $data['type'] = $this->type ?? null;
100
        }
101
        if ($this->data !== null) {
102
            $data['data'] = $this->data->toArray() ?? null;
103
        }
104
105
        return $data;
106
    }
107
108
    /**
109
     * Create an API response object from the HTTP response from the API server.
110
     *
111
     * @param array $data
112
     *
113
     * @return self
114
     */
115 3
    public static function createFromArray(array $data)
116
    {
117 3
        $event = new self();
118 3
        $event->type = $data['type'];
119 3
        $event->createdAt = $data['created_at'];
120 3
        $event->data = EventData::createFromArray($data['data']);
121
122 3
        return $event;
123
    }
124
}
125