Completed
Pull Request — master (#245)
by Tobias
07:56
created

Event::create()   F

Complexity

Conditions 18
Paths > 20000

Size

Total Lines 58
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 58
rs 3.2528
c 0
b 0
f 0
cc 18
eloc 37
nc 131072
nop 1

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Mailgun\Resource\Api\Event;
4
5
/**
6
 * @author Tobias Nyholm <[email protected]>
7
 */
8
class Event
9
{
10
    /**
11
     * @var string status
12
     */
13
    private $event;
14
15
    /**
16
     * @var string
17
     */
18
    private $id;
19
20
    /**
21
     * @var float
22
     */
23
    private $timestamp;
24
25
    /**
26
     * A \DateTime representation of $timestamp.
27
     *
28
     * @var \DateTime
29
     */
30
    private $eventDate;
31
32
    /**
33
     * @var array|string[]
34
     */
35
    private $tags = [];
36
37
    /**
38
     * @var string
39
     */
40
    private $url;
41
42
    /**
43
     * @var string
44
     */
45
    private $severity;
46
47
    /**
48
     * @var array
49
     */
50
    private $envelope = [];
51
52
    /**
53
     * @var array
54
     */
55
    private $deliveryStatus;
56
57
    /**
58
     * @var array|string[]
59
     */
60
    private $campaigns = [];
61
62
    /**
63
     * @var string
64
     */
65
    private $ip;
66
67
    /**
68
     * @var array
69
     */
70
    private $clientInfo = [];
71
72
    /**
73
     * @var string
74
     */
75
    private $reason;
76
77
    /**
78
     * @var array
79
     */
80
    private $userVariables = [];
81
82
    /**
83
     * @var array key=>bool
84
     */
85
    private $flags = [];
86
87
    /**
88
     * @var array multi dimensions
89
     */
90
    private $routes = [];
91
92
    /**
93
     * @var array multi dimensions
94
     */
95
    private $message = [];
96
97
    /**
98
     * @var string
99
     */
100
    private $recipient;
101
102
    /**
103
     * @var array
104
     */
105
    private $geolocation = [];
106
107
    /**
108
     * @var array
109
     */
110
    private $storage = [];
111
112
    /**
113
     * @var string
114
     */
115
    private $method;
116
117
    /**
118
     * @param string $event
119
     * @param string $id
120
     * @param float  $timestamp
121
     */
122
    public function __construct($event, $id, $timestamp)
123
    {
124
        $this->event = $event;
125
        $this->id = $id;
126
        $this->timestamp = $timestamp;
127
        $this->eventDate = new \DateTime();
128
        $this->eventDate->setTimestamp((int) $timestamp);
129
    }
130
131
    /**
132
     * @param array $data
133
     *
134
     * @return Event
135
     */
136
    public static function create(array $data)
137
    {
138
        $event = new self($data['event'], $data['id'], $data['timestamp']);
139
140
        if (isset($data['tags'])) {
141
            $event->setTags($data['tags']);
142
        }
143
        if (isset($data['envelope'])) {
144
            $event->setEnvelope($data['envelope']);
145
        }
146
        if (isset($data['campaigns'])) {
147
            $event->setCampaigns($data['campaigns']);
148
        }
149
        if (isset($data['user-variables'])) {
150
            $event->setUserVariables($data['user-variables']);
151
        }
152
        if (isset($data['flags'])) {
153
            $event->setFlags($data['flags']);
154
        }
155
        if (isset($data['routes'])) {
156
            $event->setRoutes($data['routes']);
157
        }
158
        if (isset($data['message'])) {
159
            $event->setMessage($data['message']);
160
        }
161
        if (isset($data['recipient'])) {
162
            $event->setRecipient($data['recipient']);
163
        }
164
        if (isset($data['method'])) {
165
            $event->setMethod($data['method']);
166
        }
167
        if (isset($data['delivery-status'])) {
168
            $event->setDeliveryStatus($data['delivery-status']);
169
        }
170
        if (isset($data['severity'])) {
171
            $event->setSeverity($data['severity']);
172
        }
173
        if (isset($data['reason'])) {
174
            $event->setReason($data['reason']);
175
        }
176
        if (isset($data['geolocation'])) {
177
            $event->setGeolocation($data['geolocation']);
178
        }
179
        if (isset($data['ip'])) {
180
            $event->setIp($data['ip']);
181
        }
182
        if (isset($data['client-info'])) {
183
            $event->setClientInfo($data['client-info']);
184
        }
185
        if (isset($data['url'])) {
186
            $event->setUrl($data['url']);
187
        }
188
        if (isset($data['storage'])) {
189
            $event->setStorage($data['storage']);
190
        }
191
192
        return $event;
193
    }
194
195
    /**
196
     * @return string
197
     */
198
    public function getEvent()
199
    {
200
        return $this->event;
201
    }
202
203
    /**
204
     * @return string
205
     */
206
    public function getId()
207
    {
208
        return $this->id;
209
    }
210
211
    /**
212
     * @return float
213
     */
214
    public function getTimestamp()
215
    {
216
        return $this->timestamp;
217
    }
218
219
    /**
220
     * @return \DateTime
221
     */
222
    public function getEventDate()
223
    {
224
        return $this->eventDate;
225
    }
226
227
    /**
228
     * @return array|\string[]
229
     */
230
    public function getTags()
231
    {
232
        return $this->tags;
233
    }
234
235
    /**
236
     * @param array|\string[] $tags
237
     */
238
    private function setTags($tags)
239
    {
240
        $this->tags = $tags;
241
    }
242
243
    /**
244
     * @return string
245
     */
246
    public function getUrl()
247
    {
248
        return $this->url;
249
    }
250
251
    /**
252
     * @param string $url
253
     */
254
    private function setUrl($url)
255
    {
256
        $this->url = $url;
257
    }
258
259
    /**
260
     * @return array
261
     */
262
    public function getEnvelope()
263
    {
264
        return $this->envelope;
265
    }
266
267
    /**
268
     * @param array $envelope
269
     */
270
    private function setEnvelope($envelope)
271
    {
272
        $this->envelope = $envelope;
273
    }
274
275
    /**
276
     * @return array
277
     */
278
    public function getDeliveryStatus()
279
    {
280
        return $this->deliveryStatus;
281
    }
282
283
    /**
284
     * @param array $deliveryStatus
285
     */
286
    private function setDeliveryStatus($deliveryStatus)
287
    {
288
        $this->deliveryStatus = $deliveryStatus;
289
    }
290
291
    /**
292
     * @return array|\string[]
293
     */
294
    public function getCampaigns()
295
    {
296
        return $this->campaigns;
297
    }
298
299
    /**
300
     * @param array|\string[] $campaigns
301
     */
302
    private function setCampaigns($campaigns)
303
    {
304
        $this->campaigns = $campaigns;
305
    }
306
307
    /**
308
     * @return string
309
     */
310
    public function getIp()
311
    {
312
        return $this->ip;
313
    }
314
315
    /**
316
     * @param string $ip
317
     */
318
    private function setIp($ip)
319
    {
320
        $this->ip = $ip;
321
    }
322
323
    /**
324
     * @return array
325
     */
326
    public function getClientInfo()
327
    {
328
        return $this->clientInfo;
329
    }
330
331
    /**
332
     * @param array $clientInfo
333
     */
334
    private function setClientInfo($clientInfo)
335
    {
336
        $this->clientInfo = $clientInfo;
337
    }
338
339
    /**
340
     * @return string
341
     */
342
    public function getReason()
343
    {
344
        return $this->reason;
345
    }
346
347
    /**
348
     * @param string $reason
349
     */
350
    private function setReason($reason)
351
    {
352
        $this->reason = $reason;
353
    }
354
355
    /**
356
     * @return array
357
     */
358
    public function getUserVariables()
359
    {
360
        return $this->userVariables;
361
    }
362
363
    /**
364
     * @param array $userVariables
365
     */
366
    private function setUserVariables($userVariables)
367
    {
368
        $this->userVariables = $userVariables;
369
    }
370
371
    /**
372
     * @return array
373
     */
374
    public function getFlags()
375
    {
376
        return $this->flags;
377
    }
378
379
    /**
380
     * @param array $flags
381
     */
382
    private function setFlags($flags)
383
    {
384
        $this->flags = $flags;
385
    }
386
387
    /**
388
     * @return array
389
     */
390
    public function getRoutes()
391
    {
392
        return $this->routes;
393
    }
394
395
    /**
396
     * @param array $routes
397
     */
398
    private function setRoutes($routes)
399
    {
400
        $this->routes = $routes;
401
    }
402
403
    /**
404
     * @return array
405
     */
406
    public function getMessage()
407
    {
408
        return $this->message;
409
    }
410
411
    /**
412
     * @param array $message
413
     */
414
    private function setMessage($message)
415
    {
416
        $this->message = $message;
417
    }
418
419
    /**
420
     * @return string
421
     */
422
    public function getRecipient()
423
    {
424
        return $this->recipient;
425
    }
426
427
    /**
428
     * @param string $recipient
429
     */
430
    private function setRecipient($recipient)
431
    {
432
        $this->recipient = $recipient;
433
    }
434
435
    /**
436
     * @return array
437
     */
438
    public function getGeolocation()
439
    {
440
        return $this->geolocation;
441
    }
442
443
    /**
444
     * @param array $geolocation
445
     */
446
    private function setGeolocation($geolocation)
447
    {
448
        $this->geolocation = $geolocation;
449
    }
450
451
    /**
452
     * @return array
453
     */
454
    public function getStorage()
455
    {
456
        return $this->storage;
457
    }
458
459
    /**
460
     * @param array $storage
461
     */
462
    private function setStorage($storage)
463
    {
464
        $this->storage = $storage;
465
    }
466
467
    /**
468
     * @return string
469
     */
470
    public function getMethod()
471
    {
472
        return $this->method;
473
    }
474
475
    /**
476
     * @param string $method
477
     */
478
    private function setMethod($method)
479
    {
480
        $this->method = $method;
481
    }
482
483
    /**
484
     * @return string
485
     */
486
    public function getSeverity()
487
    {
488
        return $this->severity;
489
    }
490
491
    /**
492
     * @param string $severity
493
     */
494
    private function setSeverity($severity)
495
    {
496
        $this->severity = $severity;
497
    }
498
}
499