MailgunEvent   F
last analyzed

Complexity

Total Complexity 69

Size/Duplication

Total Lines 924
Duplicated Lines 0 %

Test Coverage

Coverage 33.33%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 140
c 2
b 0
f 0
dl 0
loc 924
ccs 6
cts 18
cp 0.3333
rs 2.88
wmc 69

64 Methods

Rating   Name   Duplication   Size   Complexity  
A setMessageHeaders() 0 9 2
A getDateTime() 0 3 1
A getEventTitle() 0 9 2
A getMessageHeaders() 0 7 2
A setSignature() 0 5 1
A setRegion() 0 7 2
A getRecipient() 0 3 1
A setClientOs() 0 5 1
A getErrorCode() 0 3 1
A __construct() 0 4 1
A setIp() 0 5 1
A getVariables() 0 3 1
A getMailingList() 0 3 1
A getClientName() 0 3 1
A removeVariable() 0 3 1
A setClientType() 0 5 1
A getCountry() 0 3 1
A getRegion() 0 3 1
A getCampaignId() 0 3 1
A getCity() 0 3 1
A getAttachments() 0 3 1
A setReason() 0 5 1
A getClientType() 0 3 1
A setErrorCode() 0 5 1
A getMessageId() 0 3 1
A setCampaignId() 0 5 1
A setCountry() 0 7 2
A getClientOs() 0 3 1
A getTimestamp() 0 3 1
A getCampaignName() 0 3 1
A getDescription() 0 3 1
A setDomain() 0 5 1
A getReason() 0 3 1
A setDescription() 0 5 1
A setMessageId() 0 5 1
A setToken() 0 5 1
A getSignature() 0 3 1
A addAttachment() 0 5 1
A getIp() 0 3 1
A getUserAgent() 0 3 1
A setCity() 0 5 1
A getToken() 0 3 1
A getUrl() 0 3 1
A setUserAgent() 0 5 1
A setCampaignName() 0 5 1
A setTag() 0 5 1
A setMailingList() 0 5 1
A getEvent() 0 3 1
A getTag() 0 3 1
A setRecipient() 0 5 1
A removeAttachment() 0 3 1
A setTimestamp() 0 5 1
A getDomain() 0 3 1
A getDeviceType() 0 3 1
A setDeviceType() 0 5 1
A setClientName() 0 5 1
A setEvent() 0 5 1
A addVariable() 0 5 1
A setUrl() 0 5 1
A getId() 0 3 1
A setSender() 0 5 1
A getSender() 0 3 1
A setEventSummary() 0 5 1
A getEventSummary() 0 3 1

How to fix   Complexity   

Complex Class

Complex classes like MailgunEvent often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use MailgunEvent, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Azine\MailgunWebhooksBundle\Entity;
4
5
/**
6
 * MailgunEvent.
7
 */
8
class MailgunEvent
9
{
10
    const CREATE_EVENT = 'azine.mailgun.webhooks.event.create';
11
    const SEVERITY_INFO = 'info';
12
    const SEVERITY_WARN = 'warning';
13
    const SEVERITY_ERROR = 'error';
14
15
    public function getEventTitle()
16
    {
17
        $title = '';
18
        $headers = $this->getMessageHeaders();
19
        if (array_key_exists('Subject', $headers)) {
20
            $title = $headers['Subject'];
21
        }
22
23
        return $title;
24
    }
25
26
    /**
27
     * Set messageHeaders.
28
     *
29
     * In the loop, the values can also be an array.
30
     *
31
     * @param string $messageHeaders
32
     *
33
     * @return \Azine\MailgunWebhooksBundle\Entity\MailgunEvent
34
     */
35 1
    public function setMessageHeaders($messageHeaders)
36
    {
37 1
        $headers = json_decode($messageHeaders, true);
38 1
        $this->messageHeaders = array();
39 1
        foreach ($headers as $key => $value) {
40 1
            $this->messageHeaders[$key] = $value;
41
        }
42
43 1
        return $this;
44
    }
45
46
    public function getDateTime()
47
    {
48
        return new \DateTime('@'.$this->getTimestamp());
49
    }
50
51
    /**
52
     * Get messageHeaders.
53
     *
54
     * @return array
55
     */
56
    public function getMessageHeaders()
57
    {
58
        if (!is_array($this->messageHeaders)) {
0 ignored issues
show
introduced by
The condition is_array($this->messageHeaders) is always true.
Loading history...
59
            $this->setMessageHeaders($this->messageHeaders);
60
        }
61
62
        return $this->messageHeaders;
63
    }
64
65
    ///////////////////////////////////////////////////////////////////
66
    // generated stuff only below this line.
67
    // @codeCoverageIgnoreStart
68
    ///////////////////////////////////////////////////////////////////
69
    /**
70
     * @var int
71
     */
72
    private $id;
73
74
    /**
75
     * @var string
76
     */
77
    private $event;
78
79
    /**
80
     * @var string
81
     */
82
    private $domain;
83
84
    /**
85
     * @var string
86
     */
87
    private $description;
88
89
    /**
90
     * @var string
91
     */
92
    private $reason;
93
94
    /**
95
     * @var string
96
     */
97
    private $recipient;
98
99
    /**
100
     * @var string
101
     */
102
    private $errorCode;
103
104
    /**
105
     * @var string
106
     */
107
    private $ip;
108
109
    /**
110
     * @var string
111
     */
112
    private $country;
113
114
    /**
115
     * @var string
116
     */
117
    private $city;
118
119
    /**
120
     * @var string
121
     */
122
    private $region;
123
124
    /**
125
     * @var string
126
     */
127
    private $campaignId;
128
129
    /**
130
     * @var string
131
     */
132
    private $campaignName;
133
134
    /**
135
     * @var string
136
     */
137
    private $clientName;
138
139
    /**
140
     * @var string
141
     */
142
    private $clientOs;
143
144
    /**
145
     * @var string
146
     */
147
    private $clientType;
148
149
    /**
150
     * @var string
151
     */
152
    private $deviceType;
153
154
    /**
155
     * @var string
156
     */
157
    private $mailingList;
158
159
    /**
160
     * @var array
161
     */
162
    private $messageHeaders;
163
164
    /**
165
     * @var string
166
     */
167
    private $messageId;
168
169
    /**
170
     * @var string
171
     */
172
    private $tag;
173
174
    /**
175
     * @var string
176
     */
177
    private $userAgent;
178
179
    /**
180
     * @var string
181
     */
182
    private $url;
183
184
    /**
185
     * @var string
186
     */
187
    private $token;
188
189
    /**
190
     * @var int
191
     */
192
    private $timestamp;
193
194
    /**
195
     * @var string
196
     */
197
    private $signature;
198
199
    /**
200
     * @var \Doctrine\Common\Collections\Collection
201
     */
202
    private $variables;
203
204
    /**
205
     * @var \Doctrine\Common\Collections\Collection
206
     */
207
    private $attachments;
208
209
    /**
210
     * Constructor.
211
     */
212
    public function __construct()
213
    {
214
        $this->variables = new \Doctrine\Common\Collections\ArrayCollection();
215
        $this->attachments = new \Doctrine\Common\Collections\ArrayCollection();
216
    }
217
218
    /**
219
     * Get id.
220
     *
221
     * @return int
222
     */
223
    public function getId()
224
    {
225
        return $this->id;
226
    }
227
228
    /**
229
     * Set event.
230
     *
231
     * @param string $event
232
     *
233
     * @return MailgunEvent
234
     */
235
    public function setEvent($event)
236
    {
237
        $this->event = $event;
238
239
        return $this;
240
    }
241
242
    /**
243
     * Get event.
244
     *
245
     * @return string
246
     */
247
    public function getEvent()
248
    {
249
        return $this->event;
250
    }
251
252
    /**
253
     * Set domain.
254
     *
255
     * @param string $domain
256
     *
257
     * @return MailgunEvent
258
     */
259
    public function setDomain($domain)
260
    {
261
        $this->domain = $domain;
262
263
        return $this;
264
    }
265
266
    /**
267
     * Get domain.
268
     *
269
     * @return string
270
     */
271
    public function getDomain()
272
    {
273
        return $this->domain;
274
    }
275
276
    /**
277
     * Set description.
278
     *
279
     * @param string $description
280
     *
281
     * @return MailgunEvent
282
     */
283
    public function setDescription($description)
284
    {
285
        $this->description = $description;
286
287
        return $this;
288
    }
289
290
    /**
291
     * Get description.
292
     *
293
     * @return string
294
     */
295
    public function getDescription()
296
    {
297
        return $this->description;
298
    }
299
300
    /**
301
     * Set reason.
302
     *
303
     * @param string $reason
304
     *
305
     * @return MailgunEvent
306
     */
307
    public function setReason($reason)
308
    {
309
        $this->reason = $reason;
310
311
        return $this;
312
    }
313
314
    /**
315
     * Get reason.
316
     *
317
     * @return string
318
     */
319
    public function getReason()
320
    {
321
        return $this->reason;
322
    }
323
324
    /**
325
     * Set recipient.
326
     *
327
     * @param string $recipient
328
     *
329
     * @return MailgunEvent
330
     */
331
    public function setRecipient($recipient)
332
    {
333
        $this->recipient = $recipient;
334
335
        return $this;
336
    }
337
338
    /**
339
     * Get recipient.
340
     *
341
     * @return string
342
     */
343
    public function getRecipient()
344
    {
345
        return $this->recipient;
346
    }
347
348
    /**
349
     * Set errorCode.
350
     *
351
     * @param string $errorCode
352
     *
353
     * @return MailgunEvent
354
     */
355
    public function setErrorCode($errorCode)
356
    {
357
        $this->errorCode = $errorCode;
358
359
        return $this;
360
    }
361
362
    /**
363
     * Get errorCode.
364
     *
365
     * @return string
366
     */
367
    public function getErrorCode()
368
    {
369
        return $this->errorCode;
370
    }
371
372
    /**
373
     * Set ip.
374
     *
375
     * @param string $ip
376
     *
377
     * @return MailgunEvent
378
     */
379
    public function setIp($ip)
380
    {
381
        $this->ip = $ip;
382
383
        return $this;
384
    }
385
386
    /**
387
     * Get ip.
388
     *
389
     * @return string
390
     */
391
    public function getIp()
392
    {
393
        return $this->ip;
394
    }
395
396
    /**
397
     * Set country, if not Unknown.
398
     *
399
     * @param string $country
400
     *
401
     * @return MailgunEvent
402
     */
403
    public function setCountry($country)
404
    {
405
        if ('Unknown' !== $country) {
406
            $this->country = $country;
407
        }
408
409
        return $this;
410
    }
411
412
    /**
413
     * Get country.
414
     *
415
     * @return string
416
     */
417
    public function getCountry()
418
    {
419
        return $this->country;
420
    }
421
422
    /**
423
     * Set city.
424
     *
425
     * @param string $city
426
     *
427
     * @return MailgunEvent
428
     */
429
    public function setCity($city)
430
    {
431
        $this->city = $city;
432
433
        return $this;
434
    }
435
436
    /**
437
     * Get city.
438
     *
439
     * @return string
440
     */
441
    public function getCity()
442
    {
443
        return $this->city;
444
    }
445
446
    /**
447
     * Set region, if not Unknown.
448
     *
449
     * @param string $region
450
     *
451
     * @return MailgunEvent
452
     */
453
    public function setRegion($region)
454
    {
455
        if ('Unknown' !== $region) {
456
            $this->region = $region;
457
        }
458
459
        return $this;
460
    }
461
462
    /**
463
     * Get region.
464
     *
465
     * @return string
466
     */
467
    public function getRegion()
468
    {
469
        return $this->region;
470
    }
471
472
    /**
473
     * Set campaignId.
474
     *
475
     * @param string $campaignId
476
     *
477
     * @return MailgunEvent
478
     */
479
    public function setCampaignId($campaignId)
480
    {
481
        $this->campaignId = $campaignId;
482
483
        return $this;
484
    }
485
486
    /**
487
     * Get campaignId.
488
     *
489
     * @return string
490
     */
491
    public function getCampaignId()
492
    {
493
        return $this->campaignId;
494
    }
495
496
    /**
497
     * Set campaignName.
498
     *
499
     * @param string $campaignName
500
     *
501
     * @return MailgunEvent
502
     */
503
    public function setCampaignName($campaignName)
504
    {
505
        $this->campaignName = $campaignName;
506
507
        return $this;
508
    }
509
510
    /**
511
     * Get campaignName.
512
     *
513
     * @return string
514
     */
515
    public function getCampaignName()
516
    {
517
        return $this->campaignName;
518
    }
519
520
    /**
521
     * Set clientName.
522
     *
523
     * @param string $clientName
524
     *
525
     * @return MailgunEvent
526
     */
527
    public function setClientName($clientName)
528
    {
529
        $this->clientName = $clientName;
530
531
        return $this;
532
    }
533
534
    /**
535
     * Get clientName.
536
     *
537
     * @return string
538
     */
539
    public function getClientName()
540
    {
541
        return $this->clientName;
542
    }
543
544
    /**
545
     * Set clientOs.
546
     *
547
     * @param string $clientOs
548
     *
549
     * @return MailgunEvent
550
     */
551
    public function setClientOs($clientOs)
552
    {
553
        $this->clientOs = $clientOs;
554
555
        return $this;
556
    }
557
558
    /**
559
     * Get clientOs.
560
     *
561
     * @return string
562
     */
563
    public function getClientOs()
564
    {
565
        return $this->clientOs;
566
    }
567
568
    /**
569
     * Set clientType.
570
     *
571
     * @param string $clientType
572
     *
573
     * @return MailgunEvent
574
     */
575
    public function setClientType($clientType)
576
    {
577
        $this->clientType = $clientType;
578
579
        return $this;
580
    }
581
582
    /**
583
     * Get clientType.
584
     *
585
     * @return string
586
     */
587
    public function getClientType()
588
    {
589
        return $this->clientType;
590
    }
591
592
    /**
593
     * Set deviceType.
594
     *
595
     * @param string $deviceType
596
     *
597
     * @return MailgunEvent
598
     */
599
    public function setDeviceType($deviceType)
600
    {
601
        $this->deviceType = $deviceType;
602
603
        return $this;
604
    }
605
606
    /**
607
     * Get deviceType.
608
     *
609
     * @return string
610
     */
611
    public function getDeviceType()
612
    {
613
        return $this->deviceType;
614
    }
615
616
    /**
617
     * Set mailingList.
618
     *
619
     * @param string $mailingList
620
     *
621
     * @return MailgunEvent
622
     */
623
    public function setMailingList($mailingList)
624
    {
625
        $this->mailingList = $mailingList;
626
627
        return $this;
628
    }
629
630
    /**
631
     * Get mailingList.
632
     *
633
     * @return string
634
     */
635
    public function getMailingList()
636
    {
637
        return $this->mailingList;
638
    }
639
640
    /**
641
     * Set messageId.
642
     *
643
     * @param string $messageId
644
     *
645
     * @return MailgunEvent
646
     */
647
    public function setMessageId($messageId)
648
    {
649
        $this->messageId = $messageId;
650
651
        return $this;
652
    }
653
654
    /**
655
     * Get messageId.
656
     *
657
     * @return string
658
     */
659
    public function getMessageId()
660
    {
661
        return $this->messageId;
662
    }
663
664
    /**
665
     * Set tag.
666
     *
667
     * @param string $tag
668
     *
669
     * @return MailgunEvent
670
     */
671
    public function setTag($tag)
672
    {
673
        $this->tag = $tag;
674
675
        return $this;
676
    }
677
678
    /**
679
     * Get tag.
680
     *
681
     * @return string
682
     */
683
    public function getTag()
684
    {
685
        return $this->tag;
686
    }
687
688
    /**
689
     * Set userAgent.
690
     *
691
     * @param string $userAgent
692
     *
693
     * @return MailgunEvent
694
     */
695
    public function setUserAgent($userAgent)
696
    {
697
        $this->userAgent = $userAgent;
698
699
        return $this;
700
    }
701
702
    /**
703
     * Get userAgent.
704
     *
705
     * @return string
706
     */
707
    public function getUserAgent()
708
    {
709
        return $this->userAgent;
710
    }
711
712
    /**
713
     * Set url.
714
     *
715
     * @param string $url
716
     *
717
     * @return MailgunEvent
718
     */
719
    public function setUrl($url)
720
    {
721
        $this->url = $url;
722
723
        return $this;
724
    }
725
726
    /**
727
     * Get url.
728
     *
729
     * @return string
730
     */
731
    public function getUrl()
732
    {
733
        return $this->url;
734
    }
735
736
    /**
737
     * Set token.
738
     *
739
     * @param string $token
740
     *
741
     * @return MailgunEvent
742
     */
743
    public function setToken($token)
744
    {
745
        $this->token = $token;
746
747
        return $this;
748
    }
749
750
    /**
751
     * Get token.
752
     *
753
     * @return string
754
     */
755
    public function getToken()
756
    {
757
        return $this->token;
758
    }
759
760
    /**
761
     * Set timestamp.
762
     *
763
     * @param int $timestamp
764
     *
765
     * @return MailgunEvent
766
     */
767
    public function setTimestamp($timestamp)
768
    {
769
        $this->timestamp = $timestamp;
770
771
        return $this;
772
    }
773
774
    /**
775
     * Get timestamp.
776
     *
777
     * @return int
778
     */
779
    public function getTimestamp()
780
    {
781
        return $this->timestamp;
782
    }
783
784
    /**
785
     * Set signature.
786
     *
787
     * @param string $signature
788
     *
789
     * @return MailgunEvent
790
     */
791
    public function setSignature($signature)
792
    {
793
        $this->signature = $signature;
794
795
        return $this;
796
    }
797
798
    /**
799
     * Get signature.
800
     *
801
     * @return string
802
     */
803
    public function getSignature()
804
    {
805
        return $this->signature;
806
    }
807
808
    /**
809
     * Add variables.
810
     *
811
     * @param \Azine\MailgunWebhooksBundle\Entity\MailgunCustomVariable $variables
812
     *
813
     * @return MailgunEvent
814
     */
815
    public function addVariable(MailgunCustomVariable $variables)
816
    {
817
        $this->variables[] = $variables;
818
819
        return $this;
820
    }
821
822
    /**
823
     * Remove variables.
824
     *
825
     * @param \Azine\MailgunWebhooksBundle\Entity\MailgunCustomVariable $variables
826
     */
827
    public function removeVariable(MailgunCustomVariable $variables)
828
    {
829
        $this->variables->removeElement($variables);
830
    }
831
832
    /**
833
     * Get variables.
834
     *
835
     * @return \Doctrine\Common\Collections\Collection
836
     */
837
    public function getVariables()
838
    {
839
        return $this->variables;
840
    }
841
842
    /**
843
     * Add attachments.
844
     *
845
     * @param \Azine\MailgunWebhooksBundle\Entity\MailgunAttachment $attachments
846
     *
847
     * @return MailgunEvent
848
     */
849
    public function addAttachment(MailgunAttachment $attachments)
850
    {
851
        $this->attachments[] = $attachments;
852
853
        return $this;
854
    }
855
856
    /**
857
     * Remove attachments.
858
     *
859
     * @param \Azine\MailgunWebhooksBundle\Entity\MailgunAttachment $attachments
860
     */
861
    public function removeAttachment(MailgunAttachment $attachments)
862
    {
863
        $this->attachments->removeElement($attachments);
864
    }
865
866
    /**
867
     * Get attachments.
868
     *
869
     * @return \Doctrine\Common\Collections\Collection
870
     */
871
    public function getAttachments()
872
    {
873
        return $this->attachments;
874
    }
875
876
    /**
877
     * @var \Azine\MailgunWebhooksBundle\Entity\MailgunMessageSummary
878
     */
879
    private $eventSummary;
880
881
    /**
882
     * Set eventSummary.
883
     *
884
     * @param \Azine\MailgunWebhooksBundle\Entity\MailgunMessageSummary $eventSummary
885
     *
886
     * @return MailgunEvent
887
     */
888
    public function setEventSummary(MailgunMessageSummary $eventSummary = null)
889
    {
890
        $this->eventSummary = $eventSummary;
891
892
        return $this;
893
    }
894
895
    /**
896
     * Get eventSummary.
897
     *
898
     * @return \Azine\MailgunWebhooksBundle\Entity\MailgunMessageSummary
899
     */
900
    public function getEventSummary()
901
    {
902
        return $this->eventSummary;
903
    }
904
905
    /**
906
     * @var string
907
     */
908
    private $sender;
909
910
    /**
911
     * Set sender.
912
     *
913
     * @param string $sender
914
     *
915
     * @return MailgunEvent
916
     */
917
    public function setSender($sender)
918
    {
919
        $this->sender = $sender;
920
921
        return $this;
922
    }
923
924
    /**
925
     * Get sender.
926
     *
927
     * @return string
928
     */
929
    public function getSender()
930
    {
931
        return $this->sender;
932
    }
933
}
934