Passed
Push — master ( 17c5f7...cb633b )
by Stefan
04:29 queued 02:00
created

RatedShipment::__construct()   F

Complexity

Conditions 18
Paths 9217

Size

Total Lines 64
Code Lines 41

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 199.6665

Importance

Changes 0
Metric Value
dl 0
loc 64
ccs 10
cts 57
cp 0.1754
rs 2.8531
c 0
b 0
f 0
cc 18
eloc 41
nc 9217
nop 1
crap 199.6665

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 Ups\Entity;
4
5
class RatedShipment
6
{
7
    public $Service;
8
    public $RateShipmentWarning;
9
    public $BillingWeight;
10
    public $TransportationCharges;
11
    public $ServiceOptionsCharges;
12
    public $TotalCharges;
13
    public $GuaranteedDaysToDelivery;
14
    public $ScheduledDeliveryTime;
15
    public $RatedPackage;
16
    public $SurCharges;
17
    public $TimeInTransit;
18
19
    /**
20
     * @var NegotiatedRates|null
21
     */
22
    public $NegotiatedRates;
23
24 1
    public function __construct($response = null)
25
    {
26 1
        $this->Service = new Service();
27 1
        $this->BillingWeight = new BillingWeight();
28 1
        $this->TransportationCharges = new Charges();
29 1
        $this->ServiceOptionsCharges = new Charges();
30 1
        $this->TotalCharges = new Charges();
31 1
        $this->RatedPackage = [];
32 1
        $this->SurCharges = [];
33
34 1
        if (null !== $response) {
35
            if (isset($response->Service)) {
36
                $this->Service->setCode($response->Service->Code);
37
            }
38
            if (isset($response->RatedShipmentWarning)) {
39
                $this->RateShipmentWarning = $response->RatedShipmentWarning;
40
            }
41
            if (isset($response->BillingWeight)) {
42
                $this->BillingWeight = new BillingWeight($response->BillingWeight);
43
            }
44
            if (isset($response->GuaranteedDaysToDelivery)) {
45
                $this->GuaranteedDaysToDelivery = $response->GuaranteedDaysToDelivery;
46
            }
47
            if (isset($response->ScheduledDeliveryTime)) {
48
                $this->ScheduledDeliveryTime = $response->ScheduledDeliveryTime;
49
            }
50
            if (isset($response->TransportationCharges)) {
51
                $this->TransportationCharges = new Charges($response->TransportationCharges);
52
            }
53
            if (isset($response->ServiceOptionsCharges)) {
54
                $this->ServiceOptionsCharges = new Charges($response->ServiceOptionsCharges);
55
            }
56
            if (isset($response->TotalCharges)) {
57
                $this->TotalCharges = new Charges($response->TotalCharges);
58
            }
59
            if (isset($response->RatedPackage)) {
60
                if (is_array($response->RatedPackage)) {
61
                    foreach ($response->RatedPackage as $ratedPackage) {
62
                        $this->RatedPackage[] = new RatedPackage($ratedPackage);
63
                    }
64
                } else {
65
                    $this->RatedPackage[] = new RatedPackage($response->RatedPackage);
66
                }
67
            }
68
69
            if (isset($response->SurCharges)) {
70
                if (is_array($response->SurCharges)) {
71
                    foreach ($response->SurCharges as $surCharges) {
72
                        $this->SurCharges[] = new Charges($surCharges);
73
                    }
74
                } else {
75
                    $this->SurCharges[] = new Charges($response->SurCharges);
76
                }
77
            }
78
79
            if (isset($response->TimeInTransit)) {
80
                $this->TimeInTransit = new RateTimeInTransitResponse($response->TimeInTransit);
81
            }
82
83
            if (isset($response->NegotiatedRates)) {
84
                $this->NegotiatedRates = new NegotiatedRates($response->NegotiatedRates);
85
            }
86
        }
87 1
    }
88
89
    public function getServiceName()
90
    {
91
        return $this->Service->getName();
92
    }
93
}
94