Passed
Push — master ( 43d504...19d623 )
by Stefan
03:01
created

PackageServiceOptions::toNode()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 7.5412

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 8
cts 15
cp 0.5333
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 11
nc 16
nop 1
crap 7.5412
1
<?php
2
3
namespace Ups\Entity;
4
5
use DOMDocument;
6
use DOMElement;
7
use Ups\NodeInterface;
8
9
/**
10
 * Class PackageServiceOptions
11
 * @package Ups\Entity
12
 */
13
class PackageServiceOptions implements NodeInterface
14
{
15
    /**
16
     * @var COD
17
     */
18
    private $cod;
19
20
    /**
21
     * @var InsuredValue
22
     */
23
    private $insuredValue;
24
25
    /**
26
     * @var string
27
     */
28
    private $earliestDeliveryTime;
29
30
    /**
31
     * @var HazMat[]
32
     */
33
    private $hazMat = [];
34
35
    /**
36
     * @var HazMatPackageInformation
37
     */
38
    private $hazMatPackageInformation;
39
40
    /**
41
     * @var string
42
     */
43
    private $holdForPickup;
44
45
    /**
46
     * @param null $parameters
47
     */
48 2
    public function __construct($parameters = null)
49
    {
50 2
        if (null !== $parameters) {
51
            if (isset($parameters->COD)) {
52
                $this->setCOD(new COD($parameters->COD));
53
            }
54
            if (isset($parameters->InsuredValue)) {
55
                $this->setInsuredValue(new InsuredValue($parameters->InsuredValue));
56
            }
57
            if (isset($parameters->EarliestDeliveryTime)) {
58
                $this->setEarliestDeliveryTime($parameters->EarliestDeliveryTime);
59
            }
60
            if (isset($parameters->HoldForPickup)) {
61
                $this->setHoldForPickup($parameters->HoldForPickup);
62
            }
63
        }
64 2
    }
65
66
    /**
67
     * @param null|DOMDocument $document
68
     *
69
     * @TODO: this seem to be awfully incomplete
70
     *
71
     * @return DOMElement
72
     */
73 2
    public function toNode(DOMDocument $document = null)
74
    {
75 2
        if (null === $document) {
76
            $document = new DOMDocument();
77
        }
78
79 2
        $node = $document->createElement('PackageServiceOptions');
80
81 2
        if ($this->getInsuredValue()) {
82
            $node->appendChild($this->getInsuredValue()->toNode($document));
83
        }
84 2
        foreach ($this->getHazMat() as $hazmat) {
85
            $node->appendChild($hazmat->toNode($document));
86 2
        }
87 2
        if ($this->getHazMatPackageInformation() !== null) {
88
            $node->appendChild($this->getHazMatPackageInformation()->toNode($document));
89
        }
90
91 2
        return $node;
92
    }
93
94
    /**
95
     * @return InsuredValue|null
96
     */
97 2
    public function getInsuredValue()
98
    {
99 2
        return $this->insuredValue;
100
    }
101
102
    /**
103
     * @param $var
104
     */
105
    public function setInsuredValue($var)
106
    {
107
        $this->insuredValue = $var;
108
    }
109
110
    /**
111
     * @return COD|null
112
     */
113
    public function getCOD()
114
    {
115
        return $this->cod;
116
    }
117
118
    /**
119
     * @param $var
120
     */
121
    public function setCOD($var)
122
    {
123
        $this->cod = $var;
124
    }
125
126
    /**
127
     * @return string|null
128
     */
129
    public function getEarliestDeliveryTime()
130
    {
131
        return $this->earliestDeliveryTime;
132
    }
133
134
    /**
135
     * @param $var
136
     */
137
    public function setEarliestDeliveryTime($var)
138
    {
139
        $this->earliestDeliveryTime = $var;
140
    }
141
142
    /**
143
     * @return HazMat[]
144
     */
145 2
    public function getHazMat()
146
    {
147 2
        return $this->hazMat;
148
    }
149
150
    /**
151
     * @param HazMat[] $hazMat
152
     */
153
    public function setHazMat(array $hazMat)
154
    {
155
        $this->hazMat = $hazMat;
156
    }
157
158
    /**
159
     * @param HazMat $hazmat
160
     */
161
    public function addHazMat(HazMat $hazmat)
162
    {
163
        $this->hazMat[] = $hazmat;
164
    }
165
166
    /**
167
     * @return string|null
168
     */
169
    public function getHoldForPickup()
170
    {
171
        return $this->holdForPickup;
172
    }
173
174
    /**
175
     * @param $var
176
     */
177
    public function setHoldForPickup($var)
178
    {
179
        $this->holdForPickup = $var;
180
    }
181
182
    /**
183
     * @return HazMatPackageInformation
184
     */
185 2
    public function getHazMatPackageInformation()
186
    {
187 2
        return $this->hazMatPackageInformation;
188
    }
189
190
    /**
191
     * @param HazMatPackageInformation $hazMatPackageInformation
192
     */
193
    public function setHazMatPackageInformation($hazMatPackageInformation)
194
    {
195
        $this->hazMatPackageInformation = $hazMatPackageInformation;
196
    }
197
}
198