Completed
Push — master ( 4b31fe...fd90eb )
by Stefan
05:33
created

ShipperFiled::setExemptionLegend()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
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 3
    public function __construct($attributes = null)
41
    {
42 3
        if (null !== $attributes) {
43 3
            if (isset($attributes->Code)) {
44 3
                $this->setCode($attributes->Code);
45 3
            }
46 3
            if (isset($attributes->Description)) {
47 3
                $this->setDescription($attributes->Description);
48 3
            }
49 3
            if (isset($attributes->PreDepartureITNNumber)) {
50 3
                $this->setPreDepartureITNNumber($attributes->PreDepartureITNNumber);
51 3
            }
52 3
            if (isset($attributes->ExemptionLegend)) {
53 3
                $this->setExemptionLegend($attributes->ExemptionLegend);
54 3
            }
55 3
        }
56 3
    }
57
58
    /**
59
     * @param null|DOMDocument $document
60
     *
61
     * @return DOMElement
62
     */
63 1
    public function toNode(DOMDocument $document = null)
64
    {
65 1
        if (null === $document) {
66
            $document = new DOMDocument();
67
        }
68
69 1
        $node = $document->createElement('ShipperFiled');
70
71 1
        $code = $this->getCode();
72 1
        if (isset($code)) {
73 1
            $node->appendChild($document->createElement('Code', $code));
74 1
        }
75
76 1
        $description = $this->getDescription();
77 1
        if (isset($description)) {
78 1
            $node->appendChild($document->createElement('Description', $description));
79 1
        }
80
81 1
        $preDepartureITNNumber = $this->getPreDepartureITNNumber();
82 1
        if (isset($code)) {
83 1
            $node->appendChild($document->createElement('PreDepartureITNNumber', $preDepartureITNNumber));
84 1
        }
85
86 1
        $exemptionLegend = $this->getExemptionLegend();
87 1
        if (isset($exemptionLegend)) {
88 1
            $node->appendChild($document->createElement('ExemptionLegend', $exemptionLegend));
89 1
        }
90
91 1
        return $node;
92
    }
93
94
    /**
95
     * @return string
96
     */
97 3
    public function getCode()
98
    {
99 3
        return $this->code;
100
    }
101
102
    /**
103
     * @param string $code
104
     *
105
     * @return $this
106
     */
107 3
    public function setCode($code)
108
    {
109 3
        $this->code = $code;
110
111 3
        return $this;
112
    }
113
114
    /**
115
     * @return string
116
     */
117 3
    public function getDescription()
118
    {
119 3
        return $this->description;
120
    }
121
122
    /**
123
     * @return string $description
124
     */
125 3
    public function setDescription($description)
126
    {
127 3
        $this->description = $description;
128
129 3
        return $this;
130
    }
131
132
    /**
133
     * @return string
134
     */
135 3
    public function getPreDepartureITNNumber()
136
    {
137 3
        return $this->preDepartureITNNumber;
138
    }
139
140
    /**
141
     * @param string $preDepartureITNNumber
142
     *
143
     * @return $this
144
     */
145 3
    public function setPreDepartureITNNumber($preDepartureITNNumber)
146
    {
147 3
        $this->preDepartureITNNumber = $preDepartureITNNumber;
148
149 3
        return $this;
150
    }
151
152
    /**
153
     * @return string
154
     */
155 3
    public function getExemptionLegend()
156
    {
157 3
        return $this->exemptionLegend;
158
    }
159
160
    /**
161
     * @return string $exemptionLegend
162
     */
163 3
    public function setExemptionLegend($exemptionLegend)
164
    {
165 3
        $this->exemptionLegend = $exemptionLegend;
166
167 3
        return $this;
168
    }
169
}
170