1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Billogram\Model\Report; |
6
|
|
|
|
7
|
|
|
use Billogram\Exception\Domain\ValidationException; |
8
|
|
|
use Billogram\Model\CreatableFromArray; |
9
|
|
|
|
10
|
|
|
class Report implements CreatableFromArray |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
private $filename; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
private $type; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
private $fileType; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
private $info; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
private $createdAt; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
private $content; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return string |
44
|
|
|
*/ |
45
|
|
|
public function getFilename() |
46
|
|
|
{ |
47
|
|
|
return $this->filename; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string $filename |
52
|
|
|
* |
53
|
|
|
* @return Report |
54
|
|
|
*/ |
55
|
|
|
public function withFilename(string $filename) |
56
|
|
|
{ |
57
|
|
|
$new = clone $this; |
58
|
|
|
$new->filename = $filename; |
59
|
|
|
|
60
|
|
|
return $new; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return string |
65
|
|
|
*/ |
66
|
|
|
public function getType() |
67
|
|
|
{ |
68
|
|
|
return $this->type; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param string $type |
73
|
|
|
* |
74
|
|
|
* @return Report |
75
|
|
|
*/ |
76
|
|
|
public function withType(string $type) |
77
|
|
|
{ |
78
|
|
|
$new = clone $this; |
79
|
|
|
$new->type = $type; |
80
|
|
|
|
81
|
|
|
return $new; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return string |
86
|
|
|
*/ |
87
|
|
|
public function getFileType() |
88
|
|
|
{ |
89
|
|
|
return $this->fileType; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param string $fileType |
94
|
|
|
* |
95
|
|
|
* @return Report |
96
|
|
|
*/ |
97
|
|
|
public function withFileType(string $fileType) |
98
|
|
|
{ |
99
|
|
|
$new = clone $this; |
100
|
|
|
$new->fileType = $fileType; |
101
|
|
|
|
102
|
|
|
return $new; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return string |
107
|
|
|
*/ |
108
|
|
|
public function getInfo() |
109
|
|
|
{ |
110
|
|
|
return $this->info; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param string $info |
115
|
|
|
* |
116
|
|
|
* @return Report |
117
|
|
|
*/ |
118
|
|
|
public function withInfo(string $info) |
119
|
|
|
{ |
120
|
|
|
$new = clone $this; |
121
|
|
|
$new->info = $info; |
122
|
|
|
|
123
|
|
|
return $new; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return string |
128
|
|
|
*/ |
129
|
|
|
public function getCreatedAt() |
130
|
|
|
{ |
131
|
|
|
return $this->createdAt; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @param string $createdAt |
136
|
|
|
* |
137
|
|
|
* @return Report |
138
|
|
|
*/ |
139
|
|
|
public function withCreatedAt(string $createdAt) |
140
|
|
|
{ |
141
|
|
|
$new = clone $this; |
142
|
|
|
$new->createdAt = $createdAt; |
143
|
|
|
|
144
|
|
|
return $new; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @return string |
149
|
|
|
*/ |
150
|
|
|
public function getContent() |
151
|
|
|
{ |
152
|
|
|
return $this->content; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @param string $content |
157
|
|
|
* |
158
|
|
|
* @return Report |
159
|
|
|
*/ |
160
|
|
|
public function withContent(string $content) |
161
|
|
|
{ |
162
|
|
|
$new = clone $this; |
163
|
|
|
$new->content = $content; |
164
|
|
|
|
165
|
|
|
return $new; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Create an API response object from the HTTP response from the API server. |
170
|
|
|
* |
171
|
|
|
* @param array $data |
172
|
|
|
* |
173
|
|
|
* @return self |
174
|
|
|
* |
175
|
|
|
* @throws ValidationException |
176
|
|
|
*/ |
177
|
1 |
|
public static function createFromArray(array $data) |
178
|
|
|
{ |
179
|
1 |
View Code Duplication |
if ($data['status'] === 'INVALID_PARAMETER' && array_key_exists('message', $data['data'])) { |
|
|
|
|
180
|
|
|
throw new ValidationException($data['data']['message']); |
181
|
|
|
} |
182
|
1 |
|
$report = new self(); |
183
|
1 |
|
$report->filename = $data['filename'] ?? null; |
184
|
1 |
|
$report->type = $data['type'] ?? null; |
185
|
1 |
|
$report->fileType = $data['file_type'] ?? null; |
186
|
1 |
|
$report->info = $data['info'] ?? null; |
187
|
1 |
|
$report->createdAt = isset($data['created_at']) ? new \DateTime($data['created_at']) : null; |
|
|
|
|
188
|
1 |
|
$report->content = $data['content'] ?? null; |
189
|
|
|
|
190
|
1 |
|
return $report; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
public function toArray() |
194
|
|
|
{ |
195
|
|
|
// TODO write me |
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.