1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ups\Entity; |
4
|
|
|
|
5
|
|
|
use DOMDocument; |
6
|
|
|
use DOMElement; |
7
|
|
|
use Ups\NodeInterface; |
8
|
|
|
|
9
|
|
|
class POA implements NodeInterface |
10
|
|
|
{ |
11
|
|
|
const POA_ONE_TIME = '1'; // One Time POA |
12
|
|
|
const POA_BLANKET = '2'; // Blanket POA |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
private $code; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
private $description; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param null|object $attributes |
26
|
|
|
*/ |
27
|
3 |
View Code Duplication |
public function __construct($attributes = null) |
|
|
|
|
28
|
|
|
{ |
29
|
3 |
|
if (null !== $attributes) { |
30
|
3 |
|
if (isset($attributes->Code)) { |
31
|
3 |
|
$this->setCode($attributes->Code); |
32
|
3 |
|
} |
33
|
3 |
|
if (isset($attributes->Description)) { |
34
|
3 |
|
$this->setDescription($attributes->Description); |
35
|
3 |
|
} |
36
|
3 |
|
} |
37
|
3 |
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param null|DOMDocument $document |
41
|
|
|
* |
42
|
|
|
* @return DOMElement |
43
|
|
|
*/ |
44
|
1 |
|
public function toNode(DOMDocument $document = null) |
45
|
|
|
{ |
46
|
1 |
|
if (null === $document) { |
47
|
|
|
$document = new DOMDocument(); |
48
|
|
|
} |
49
|
|
|
|
50
|
1 |
|
$node = $document->createElement('POA'); |
51
|
|
|
|
52
|
1 |
|
$code = $this->getCode(); |
53
|
1 |
|
if (isset($code)) { |
54
|
1 |
|
$node->appendChild($document->createElement('Code', $code)); |
55
|
1 |
|
} |
56
|
|
|
|
57
|
1 |
|
$description = $this->getDescription(); |
58
|
1 |
|
if (isset($description)) { |
59
|
1 |
|
$node->appendChild($document->createElement('Description', $description)); |
60
|
1 |
|
} |
61
|
|
|
|
62
|
1 |
|
return $node; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
3 |
|
public function getCode() |
69
|
|
|
{ |
70
|
3 |
|
return $this->code; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param string $code |
75
|
|
|
* |
76
|
|
|
* @return $this |
77
|
|
|
*/ |
78
|
3 |
|
public function setCode($code) |
79
|
|
|
{ |
80
|
3 |
|
$this->code = $code; |
81
|
|
|
|
82
|
3 |
|
return $this; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return string |
87
|
|
|
*/ |
88
|
3 |
|
public function getDescription() |
89
|
|
|
{ |
90
|
3 |
|
return $this->description; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param string $description |
95
|
|
|
* |
96
|
|
|
* @return $this |
97
|
|
|
*/ |
98
|
3 |
|
public function setDescription($description) |
99
|
|
|
{ |
100
|
3 |
|
$this->description = $description; |
101
|
|
|
|
102
|
3 |
|
return $this; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
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.