Completed
Pull Request — master (#154)
by
unknown
03:52
created

Product::setUnit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Ups\Entity;
4
5
use DOMDocument;
6
use DOMElement;
7
use Ups\NodeInterface;
8
9
/**
10
 * Class Product.
11
 */
12
class Product implements NodeInterface
13
{
14
    /**
15
     * @var string
16
     */
17
    private $description1;
18
19
    /**
20
     * @var string
21
     */
22
    private $description2;
23
24
    /**
25
     * @var string
26
     */
27
    private $description3;
28
29
    /**
30
     * @var string
31
     */
32
    private $commodityCode;
33
34
    /**
35
     * @var string
36
     */
37
    private $partNumber;
38
39
    /**
40
     * @var string
41
     */
42
    private $originCountryCode;
43
44
    /**
45
     * @var Unit
46
     */
47
    private $unit;
48
49
    /**
50
     * @var PackingListInfo
51
     */
52
    private $packingListInfo;
53
54
    /**
55
     * @param null|object $attributes
56
     */
57 1
    public function __construct($attributes = null)
58
    {
59 1
        if (null !== $attributes) {
60
            if (isset($attributes->Description)) {
61
                $this->setDescription1($attributes->Description);
62
            }
63
            if (isset($attributes->CommodityCode)) {
64
                $this->setCommodityCode($attributes->CommodityCode);
65
            }
66
            if (isset($attributes->PartNumber)) {
67
                $this->setPartNumber($attributes->PartNumber);
68
            }
69
            if (isset($attributes->OriginCountryCode)) {
70
                $this->setOriginCountryCode($attributes->OriginCountryCode);
71
            }
72
        }
73 1
    }
74
75
    /**
76
     * @param null|DOMDocument $document
77
     *
78
     * @return DOMElement
79
     */
80 1
    public function toNode(DOMDocument $document = null)
81
    {
82 1
        if (null === $document) {
83
            $document = new DOMDocument();
84
        }
85
86 1
        $node = $document->createElement('Product');
87 1
        for ($i = 1; $i <= 3; $i++) {
88 1
            $desc = $this->{'getDescription' . $i}();
89 1
            if ($desc !== null) {
90
                $node->appendChild($document->createElement('Description', $desc));
91
            }
92 1
        }
93 1
        if ($this->getUnit() !== null) {
94
            $node->appendChild($this->getUnit()->toNode($document));
95
        }
96 1
        if ($this->getCommodityCode() !== null) {
97
            $node->appendChild($document->createElement('CommodityCode', $this->getCommodityCode()));
98
        }
99 1
        if ($this->getPartNumber() !== null) {
100
            $node->appendChild($document->createElement('PartNumber', $this->getPartNumber()));
101
        }
102 1
        if ($this->getOriginCountryCode() !== null) {
103
            $node->appendChild($document->createElement('OriginCountryCode', $this->getOriginCountryCode()));
104
        }
105 1
        if ($this->getPackingListInfo()) {
106
            $node->appendChild($this->getPackingListInfo()->toNode($document));
107
        }
108
109 1
        return $node;
110
    }
111
112
    /**
113
     * @return string
114
     */
115 1
    public function getDescription1()
116
    {
117 1
        return $this->description1;
118
    }
119
120
    /**
121
     * @param string $description
122
     *
123
     * @return $this
124
     */
125 View Code Duplication
    public function setDescription1($description)
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...
126
    {
127
        if (strlen($description) > 35) {
128
            $description = substr($description, 0, 35);
129
        }
130
131
        $this->description1 = $description;
132
133
        return $this;
134
    }
135
136
    /**
137
     * @return string
138
     */
139 1
    public function getDescription2()
140
    {
141 1
        return $this->description2;
142
    }
143
144
    /**
145
     * @param string $description
146
     *
147
     * @return $this
148
     */
149 View Code Duplication
    public function setDescription2($description)
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...
150
    {
151
        if (strlen($description) > 35) {
152
            $description = substr($description, 0, 35);
153
        }
154
155
        $this->description2 = $description;
156
157
        return $this;
158
    }
159
160
    /**
161
     * @return string
162
     */
163 1
    public function getDescription3()
164
    {
165 1
        return $this->description3;
166
    }
167
168
    /**
169
     * @param string $description
170
     *
171
     * @return $this
172
     */
173 View Code Duplication
    public function setDescription3($description)
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...
174
    {
175
        if (strlen($description) > 35) {
176
            $description = substr($description, 0, 35);
177
        }
178
179
        $this->description3 = $description;
180
181
        return $this;
182
    }
183
184
    /**
185
     * @return string
186
     */
187 1
    public function getCommodityCode()
188
    {
189 1
        return $this->commodityCode;
190
    }
191
192
    /**
193
     * @param string $code
194
     *
195
     * @return $this
196
     */
197
    public function setCommodityCode($code)
198
    {
199
        $this->commodityCode = $code;
200
201
        return $this;
202
    }
203
204
    /**
205
     * @param Unit $unit
206
     *
207
     * @return $this
208
     */
209
    public function setUnit(Unit $unit)
210
    {
211
        $this->unit = $unit;
212
213
        return $this;
214
    }
215
216
    /**
217
     * @return Unit
218
     */
219 1
    public function getUnit()
220
    {
221 1
        return $this->unit;
222
    }
223
224
    /**
225
     * @param $number
226
     *
227
     * @return $this
228
     */
229
    public function setPartNumber($number)
230
    {
231
        $this->partNumber = $number;
232
233
        return $this;
234
    }
235
236
    /**
237
     * @return string
238
     */
239 1
    public function getPartNumber()
240
    {
241 1
        return $this->partNumber;
242
    }
243
244
    /**
245
     * @param string $countryCode
246
     *
247
     * @return $this
248
     */
249
    public function setOriginCountryCode($countryCode)
250
    {
251
        $this->originCountryCode = $countryCode;
252
253
        return $this;
254
    }
255
256
    /**
257
     * @return string
258
     */
259 1
    public function getOriginCountryCode()
260
    {
261 1
        return $this->originCountryCode;
262
    }
263
264
    /**
265
     * @param PackingListInfo $info
266
     *
267
     * @return $this
268
     */
269
    public function setPackingListInfo(PackingListInfo $info)
270
    {
271
        $this->packingListInfo = $info;
272
273
        return $this;
274
    }
275
276
    /**
277
     * @return PackingListInfo
278
     */
279 1
    public function getPackingListInfo()
280
    {
281 1
        return $this->packingListInfo;
282
    }
283
}
284