Completed
Pull Request — master (#86)
by
unknown
03:35
created

Generic   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 85
Duplicated Lines 21.18 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 18
c 2
b 0
f 0
lcom 0
cbo 7
dl 18
loc 85
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
F __construct() 18 61 18

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Ups\Entity;
4
5
class Generic
6
{
7
    const AT_VOIDFORMANIFEST = 'VM';
8
    const AT_UNDELIVERABLERETURNS = 'UR';
9
    const AT_INVOICEREMOVALSUCCESSFUL = 'IR';
10
    const AT_TRANSPORTCOMPANYUSPSSCAN = 'TC';
11
    const AT_POSTALSERVICEPOSSESSIONSCAN = 'PS';
12
    const AT_UPSEMAILNOTIFICATIONFAILURE = 'FN';
13
    const AT_DESTINATIONSCAN = 'DS';
14
15
    public $ActivityType;
16
    public $TrackingNumber;
17
    public $ShipperNumber;
18
    public $ShipmentReferenceNumber;
19
    public $PackageReferenceNumber;
20
    public $Service;
21
    public $Activity;
22
    public $BillToAccount;
23
    public $ShipTo;
24
    public $RescheduledDeliveryDate;
25
    public $FailureNotification;
26
    public $Bookmark;
27
28
    public function __construct($response = null)
29
    {
30
        $this->ShipmentReferenceNumber = new ShipmentReferenceNumber();
31
        $this->PackageReferenceNumber = new PackageReferenceNumber();
32
        $this->Service = new Service();
33
        $this->Activity = new Activity();
34
        $this->BillToAccount = new BillToAccount();
35
        $this->ShipTo = new ShipTo();
36
        $this->FailureNotification = new FailureNotification();
37
38
        if (null != $response) {
39
            if (isset($response->ActivityType)) {
40
                $this->ActivityType = $response->ActivityType;
41
            }
42
            if (isset($response->TrackingNumber)) {
43
                $this->TrackingNumber = $response->TrackingNumber;
44
            }
45
            if (isset($response->ShipperNumber)) {
46
                $this->ShipperNumber = $response->ShipperNumber;
47
            }
48 View Code Duplication
            if (isset($response->ShipmentReferenceNumber)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
49
                if (is_array($response->ShipmentReferenceNumber)) {
50
                    foreach ($response->ShipmentReferenceNumber as $ShipmentReferenceNumber) {
51
                        $this->ShipmentReferenceNumber[] = new ShipmentReferenceNumber($ShipmentReferenceNumber);
52
                    }
53
                } else {
54
                    $this->ShipmentReferenceNumber[] = new ShipmentReferenceNumber($response->ShipmentReferenceNumber);
55
                }
56
            }
57 View Code Duplication
            if (isset($response->PackageReferenceNumber)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
58
                if (is_array($response->PackageReferenceNumber)) {
59
                    foreach ($response->PackageReferenceNumber as $PackageReferenceNumber) {
60
                        $this->PackageReferenceNumber[] = new PackageReferenceNumber($PackageReferenceNumber);
61
                    }
62
                } else {
63
                    $this->PackageReferenceNumber[] = new PackageReferenceNumber($response->PackageReferenceNumber);
64
                }
65
            }
66
            if (isset($response->Service)) {
67
                $this->Service->setCode($response->Service->Code);
68
            }
69
            if (isset($response->Activity)) {
70
                $this->Activity = new Activity($response->Activity);
71
            }
72
            if (isset($response->BillToAccount)) {
73
                $this->BillToAccount = new BillToAccount($response->BillToAccount);
74
            }
75
            if (isset($response->ShipTo)) {
76
                $this->ShipTo = new ShipTo($response->ShipTo);
77
            }
78
            if (isset($response->RescheduledDeliveryDate)) {
79
                $this->RescheduledDeliveryDate = $response->RescheduledDeliveryDate;
80
            }
81
            if (isset($response->FailureNotification)) {
82
                $this->FailureNotification = new FailureNotification($response->FailureNotification);
83
            }
84
            if (isset($response->Bookmark)) {
85
                $this->Bookmark = $response->Bookmark;
86
            }
87
        }
88
    }
89
}
90