Service::getDescription()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php namespace SimpleUPS;
2
3
/**
4
 * The type of service a shipment was shipped with
5
 * @since 1.0
6
 */
7
class Service extends Model
8
{
9
10
    const
11
        NEXT_DAY_AIR_EARLY_AM = '14',
12
        NEXT_DAY_AIR = '01',
13
        NEXT_DAY_AIR_SAVER = '13',
14
        SECOND_DAY_AIR_AM = '59',
15
        SECOND_DAY_AIR = '02',
16
        THREE_DAY_SELECT = '12',
17
        GROUND = '03',
18
19
        INT_STANDARD = '11',
20
        INT_WORLDWIDE_EXPRESS = '07',
21
        INT_WORLDWIDE_EXPRESS_PLUS = '54',
22
        INT_WORLDWIDE_EXPEDITED = '08',
23
        INT_SAVER = '65',
24
25
        POLAND_TODAY_STANDARD = '82',
26
        POLAND_TODAY_DEDICATED_COURIER = '83',
27
        POLAND_TODAY_INTERCITY = '84',
28
        POLAND_TODAY_EXPRESS = '85',
29
        POLAND_TODAY_EXPRESS_SAVER = '86',
30
        POLAND_WORLDWIDE_EXPRESS_FREIGHT = '96';
31
32
    private
33
        /* @var string $code */
34
        $code,
35
36
        /* @var string $description */
37
        $description,
38
39
        $descriptions = array(
40
        '14' => 'Next Day Air Early AM',
41
        '01' => 'Next Day Air',
42
        '13' => 'Next Day Air Saver',
43
        '59' => 'Second Day Air AM',
44
        '02' => 'Second Day Air',
45
        '12' => 'Three Day Select',
46
        '03' => 'Ground',
47
        '11' => 'International Standard',
48
        '07' => 'International Worldwide Express',
49
        '54' => 'International Worldwide Express Plus',
50
        '08' => 'International Worldwide Expedited',
51
        '65' => 'International Saver',
52
        '82' => 'Poland Today Standard',
53
        '83' => 'Poland Today Dedicated Courier',
54
        '84' => 'Poland Today Intercity',
55
        '85' => 'Poland Today Express',
56
        '86' => 'Poland Today Express Saver',
57
        '96' => 'Poland Worldwide Express Freight'
58
    );
59
60
    /**
61
     * Set the service code
62
     * @internal
63
     *
64
     * @param string $code
65
     *
66
     * @return Service
67
     */
68
    public function setCode($code)
69
    {
70
        $this->code = (string)$code;
71
72
        if ($this->description === null && isset($this->descriptions[$this->code])) {
73
            $this->description = $this->descriptions[$this->code];
74
        }
75
76
        return $this;
77
    }
78
79
    /**
80
     * Get the service code
81
     * @return string
82
     */
83
    public function getCode()
84
    {
85
        return $this->code;
86
    }
87
88
    /**
89
     * Set the service description
90
     * @internal
91
     *
92
     * @param string $description
93
     *
94
     * @return Service
95
     */
96
    public function setDescription($description)
97
    {
98
        $this->description = (string)$description;
99
        return $this;
100
    }
101
102
    /**
103
     * Get the service description
104
     * @return string
105
     */
106
    public function getDescription()
107
    {
108
        return $this->description;
109
    }
110
111
    /**
112
     * Get service as XML
113
     * @internal
114
     *
115
     * @param \DomDocument $dom
116
     *
117
     * @return \DOMElement
118
     */
119
    public function toXml(\DomDocument $dom)
120
    {
121
        $shipper = $dom->createElement('Service');
122
123
        if ($this->getCode() != null) {
124
            $shipper->appendChild($dom->createElement('Code', $this->getCode()));
125
        }
126
127
        if ($this->getDescription() != null) {
128
            $shipper->appendChild($dom->createElement('Description', $this->getDescription()));
129
        }
130
131
        return $shipper;
132
    }
133
134
    /**
135
     * Get this object from XML
136
     * @internal
137
     *
138
     * @param \SimpleXMLElement $xml
139
     *
140
     * @return Service
141
     */
142 View Code Duplication
    public static function fromXml(\SimpleXMLElement $xml)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
143
    {
144
        $service = new Service();
145
        $service->setIsResponse();
146
        $service->setCode($xml->Code);
147
148
        if (isset($xml->Description)) {
149
            $service->setDescription($xml->Description);
150
        }
151
152
        return $service;
153
    }
154
}