Passed
Pull Request — master (#223)
by
unknown
02:52
created

Product::setProductName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

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 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Ups\Entity\Tradeability;
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
    /**
16
     * @var string
17
     */
18
    private $productName;
19
20
    /**
21
     * @var string
22
     */
23
    private $productDescription;
24
25
    /**
26
     * @var string
27
     */
28
    private $productCountryCodeOfOrigin;
29
30
    /**
31
     * @var TariffInfo
32
     */
33
    private $tariffInfo;
34
35
    /**
36
     * @var Quantity
37
     */
38
    private $quantity;
39
40
    /**
41
     * @var UnitPrice
42
     */
43
    private $unitPrice;
44
45
    /**
46
     * @var Weight
47
     */
48
    private $weight;
49
50
    /**
51
     * @var int
52
     */
53
    private $tariffCodeAlert = 0;
54
55
    /**
56
     * @param null|DOMDocument $document
57
     *
58
     * @return DOMElement
59
     */
60 1
    public function toNode(DOMDocument $document = null)
61
    {
62 1
        if (null === $document) {
63
            $document = new DOMDocument();
64
        }
65
66 1
        $node = $document->createElement('Product');
67
68
        // Required
69 1
        if ($this->getTariffInfo() !== null) {
70
            $node->appendChild($this->getTariffInfo()->toNode($document));
71
        }
72 1
        if ($this->getUnitPrice() !== null) {
73
            $node->appendChild($this->getUnitPrice()->toNode($document));
74
        }
75 1
        if ($this->getQuantity() !== null) {
76
            $node->appendChild($this->getQuantity()->toNode($document));
77
        }
78
79
        // Optional
80 1
        if ($this->getProductName() !== null) {
81
            $node->appendChild($document->createElement('ProductName', $this->getProductName()));
82
        }
83 1
        if ($this->getProductDescription() !== null) {
84
            $node->appendChild($document->createElement('ProductDescription', $this->getProductDescription()));
85
        }
86 1
        if ($this->getProductCountryCodeOfOrigin() !== null) {
87
            $node->appendChild(
88
                $document->createElement(
89
                    'ProductCountryCodeOfOrigin',
90
                    $this->getProductCountryCodeOfOrigin()
91
                )
92
            );
93
        }
94 1
        if ($this->getWeight() instanceof Weight) {
95
            $node->appendChild($this->getWeight()->toNode($document));
96
        }
97 1
        if ($this->getTariffCodeAlert() !== null) {
98 1
            $node->appendChild($document->createElement('TariffCodeAlert', $this->getTariffCodeAlert()));
99 1
        }
100
101 1
        return $node;
102
    }
103
104
    /**
105
     * @return TariffInfo
106
     */
107 1
    public function getTariffInfo()
108
    {
109 1
        return $this->tariffInfo;
110
    }
111
112
    /**
113
     * @param TariffInfo $tariffInfo
114
     * @return Product
115
     */
116
    public function setTariffInfo(TariffInfo $tariffInfo)
117
    {
118
        $this->tariffInfo = $tariffInfo;
119
120
        return $this;
121
    }
122
123
    /**
124
     * @return UnitPrice
125
     */
126 1
    public function getUnitPrice()
127
    {
128 1
        return $this->unitPrice;
129
    }
130
131
    /**
132
     * @param UnitPrice $unitPrice
133
     * @return Product
134
     */
135
    public function setUnitPrice($unitPrice)
136
    {
137
        $this->unitPrice = $unitPrice;
138
139
        return $this;
140
    }
141
142
    /**
143
     * @return Quantity
144
     */
145 1
    public function getQuantity()
146
    {
147 1
        return $this->quantity;
148
    }
149
150
    /**
151
     * @param Quantity $quantity
152
     * @return Product
153
     */
154
    public function setQuantity($quantity)
155
    {
156
        $this->quantity = $quantity;
157
158
        return $this;
159
    }
160
161
    /**
162
     * @return string
163
     */
164 1
    public function getProductName()
165
    {
166 1
        return $this->productName;
167
    }
168
169
    /**
170
     * @param string $productName
171
     * @return Product
172
     */
173
    public function setProductName($productName)
174
    {
175
        $this->productName = $productName;
176
177
        return $this;
178
    }
179
180
    /**
181
     * @return string
182
     */
183 1
    public function getProductDescription()
184
    {
185 1
        return $this->productDescription;
186
    }
187
188
    /**
189
     * @param string $productDescription
190
     * @return Product
191
     */
192
    public function setProductDescription($productDescription)
193
    {
194
        $this->productDescription = $productDescription;
195
196
        return $this;
197
    }
198
199
    /**
200
     * @return string
201
     */
202 1
    public function getProductCountryCodeOfOrigin()
203
    {
204 1
        return $this->productCountryCodeOfOrigin;
205
    }
206
207
    /**
208
     * @param string $productCountryCodeOfOrigin
209
     * @return Product
210
     */
211
    public function setProductCountryCodeOfOrigin($productCountryCodeOfOrigin)
212
    {
213
        $this->productCountryCodeOfOrigin = $productCountryCodeOfOrigin;
214
215
        return $this;
216
    }
217
218
    /**
219
     * @return Weight
220
     */
221 1
    public function getWeight()
222
    {
223 1
        return $this->weight;
224
    }
225
226
    /**
227
     * @param Weight $weight
228
     * @return Product
229
     */
230
    public function setWeight($weight)
231
    {
232
        $this->weight = $weight;
233
234
        return $this;
235
    }
236
237
    /**
238
     * @return int
239
     */
240 1
    public function getTariffCodeAlert()
241
    {
242 1
        return $this->tariffCodeAlert;
243
    }
244
245
    /**
246
     * @param int $tariffCodeAlert
247
     * @return Product
248
     */
249
    public function setTariffCodeAlert($tariffCodeAlert)
250
    {
251
        $this->tariffCodeAlert = $tariffCodeAlert;
252
253
        return $this;
254
    }
255
}
256