Passed
Push — master ( 335c74...ca5aae )
by Pierre
02:52
created

ShipperFiled::toNode()   B

Complexity

Conditions 6
Paths 32

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
dl 0
loc 30
ccs 0
cts 17
cp 0
rs 8.8177
c 0
b 0
f 0
cc 6
nc 32
nop 1
crap 42
1
<?php
2
3
namespace Ups\Entity;
4
5
use DOMDocument;
6
use DOMElement;
7
use Ups\NodeInterface;
8
9
class ShipperFiled implements NodeInterface
10
{
11
    const SF_ITN                   = 'A'; // Requires the ITN
12
    const SF_EXEMPTION_LEGEND      = 'B'; // Requires the Exemption Legend
13
    const SF_POST_DEPARTURE_FILING = 'C'; // Requires Post Departure Filing Citation
14
15
    /**
16
     * @var string
17
     */
18
    private $code;
19
20
    /**
21
     * @var string
22
     */
23
    private $description;
24
25
    /**
26
     * @var string
27
     * Required if code=SF_ITN
28
     */
29
    private $preDepartureITNNumber;
30
31
    /**
32
     * @var string
33
     * Required if code=SF_EXEMPTION_LEGEND
34
     */
35
    private $exemptionLegend;
36
37
    /**
38
     * @param null|object $attributes
39
     */
40
    public function __construct($attributes = null)
41
    {
42
        if (null !== $attributes) {
43
            if (isset($attributes->Code)) {
44
                $this->setCode($attributes->Code);
45
            }
46
            if (isset($attributes->Description)) {
47
                $this->setDescription($attributes->Description);
48
            }
49
            if (isset($attributes->PreDepartureITNNumber)) {
50
                $this->setPreDepartureITNNumber($attributes->PreDepartureITNNumber);
51
            }
52
            if (isset($attributes->ExemptionLegend)) {
53
                $this->setExemptionLegend($attributes->ExemptionLegend);
54
            }
55
        }
56
    }
57
58
    /**
59
     * @param null|DOMDocument $document
60
     *
61
     * @return DOMElement
62
     */
63
    public function toNode(DOMDocument $document = null)
64
    {
65
        if (null === $document) {
66
            $document = new DOMDocument();
67
        }
68
69
        $node = $document->createElement('ShipperFiled');
70
71
        $code = $this->getCode();
72
        if (isset($code)) {
73
            $node->appendChild($document->createElement('Code', $code));
74
        }
75
76
        $description = $this->getDescription();
77
        if (isset($description)) {
78
            $node->appendChild($document->createElement('Description', $description));
79
        }
80
81
        $preDepartureITNNumber = $this->getPreDepartureITNNumber();
82
        if (isset($code)) {
83
            $node->appendChild($document->createElement('PreDepartureITNNumber', $preDepartureITNNumber));
84
        }
85
86
        $exemptionLegend = $this->getExemptionLegend();
87
        if (isset($exemptionLegend)) {
88
            $node->appendChild($document->createElement('ExemptionLegend', $exemptionLegend));
89
        }
90
91
        return $node;
92
    }
93
94
    /**
95
     * @return string
96
     */
97
    public function getCode()
98
    {
99
        return $this->code;
100
    }
101
102
    /**
103
     * @param string $code
104
     *
105
     * @return $this
106
     */
107
    public function setCode($code)
108
    {
109
        $this->code = $code;
110
111
        return $this;
112
    }
113
114
    /**
115
     * @return string
116
     */
117
    public function getDescription()
118
    {
119
        return $this->description;
120
    }
121
122
    /**
123
     * @return string $description
124
     */
125
    public function setDescription($description)
126
    {
127
        $this->description = $description;
128
129
        return $this;
130
    }
131
132
    /**
133
     * @return string
134
     */
135
    public function getPreDepartureITNNumber()
136
    {
137
        return $this->preDepartureITNNumber;
138
    }
139
140
    /**
141
     * @param string $preDepartureITNNumber
142
     *
143
     * @return $this
144
     */
145
    public function setPreDepartureITNNumber($preDepartureITNNumber)
146
    {
147
        $this->preDepartureITNNumber = $preDepartureITNNumber;
148
149
        return $this;
150
    }
151
152
    /**
153
     * @return string
154
     */
155
    public function getExemptionLegend()
156
    {
157
        return $this->exemptionLegend;
158
    }
159
160
    /**
161
     * @return string $exemptionLegend
162
     */
163
    public function setExemptionLegend($exemptionLegend)
164
    {
165
        $this->exemptionLegend = $exemptionLegend;
166
167
        return $this;
168
    }
169
}
170