1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bpost\BpostApiClient\Bpost\ProductConfiguration; |
4
|
|
|
|
5
|
|
|
use SimpleXMLElement; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class Option |
9
|
|
|
* @package Bpost\BpostApiClient\Bpost\ProductConfiguration |
10
|
|
|
*/ |
11
|
|
|
class Option |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
const OPTION_VISIBILITY_NOT_VISIBLE_BY_CONSUMER_OPTIONAL = 'NOT_VISIBLE_BY_CONSUMER_OPTIONAL'; |
15
|
|
|
const OPTION_VISIBILITY_NOT_VISIBLE_BY_CONSUMER_DEFAULT = 'NOT_VISIBLE_BY_CONSUMER_DEFAULT'; |
16
|
|
|
const OPTION_VISIBILITY_VISIBLE_BY_CONSUMER_AND_MANDATORY = 'VISIBLE_BY_CONSUMER_AND_MANDATORY'; |
17
|
|
|
|
18
|
|
|
/** @var string */ |
19
|
|
|
private $visibility; |
20
|
|
|
/** @var int */ |
21
|
|
|
private $price; |
22
|
|
|
/** @var string */ |
23
|
|
|
private $name; |
24
|
|
|
/** @var Characteristic[] */ |
25
|
|
|
private $characteristics = array(); |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param SimpleXMLElement $xml |
29
|
|
|
* |
30
|
|
|
* @return Option |
31
|
|
|
*/ |
32
|
|
View Code Duplication |
public static function createFromXML(SimpleXMLElement $xml) |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
/* |
35
|
|
|
<option visiblity="NOT_VISIBLE_BY_CONSUMER_OPTIONAL" price="0" name="Cash on delivery"/> |
36
|
|
|
*/ |
37
|
|
|
$attributes = $xml->attributes(); |
38
|
|
|
$children = $xml->children(); |
39
|
|
|
|
40
|
|
|
$option = new self(); |
41
|
|
|
$option->setVisibility($attributes['visiblity']); |
42
|
|
|
$option->setPrice($attributes['price']); |
43
|
|
|
$option->setName($attributes['name']); |
44
|
|
|
|
45
|
|
|
if (isset($children->chracteristic)) { |
46
|
|
|
foreach ($children->chracteristic as $characteristicXml) { |
47
|
|
|
$option->addCharacteristic(Characteristic::createFromXML($characteristicXml)); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return $option; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
|
|
public function getVisibility() |
58
|
|
|
{ |
59
|
|
|
return $this->visibility; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param string $visibility |
64
|
|
|
*/ |
65
|
|
|
public function setVisibility($visibility) |
66
|
|
|
{ |
67
|
|
|
$this->visibility = (string) $visibility; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return int |
72
|
|
|
*/ |
73
|
|
|
public function getPrice() |
74
|
|
|
{ |
75
|
|
|
return $this->price; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param int $price |
80
|
|
|
*/ |
81
|
|
|
public function setPrice($price) |
82
|
|
|
{ |
83
|
|
|
$this->price = (int) $price; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return string |
88
|
|
|
*/ |
89
|
|
|
public function getName() |
90
|
|
|
{ |
91
|
|
|
return $this->name; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param string $name |
96
|
|
|
*/ |
97
|
|
|
public function setName($name) |
98
|
|
|
{ |
99
|
|
|
$this->name = (string) $name; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return Characteristic[] |
104
|
|
|
*/ |
105
|
|
|
public function getCharacteristics() |
106
|
|
|
{ |
107
|
|
|
return $this->characteristics; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param Characteristic $characteristic |
112
|
|
|
*/ |
113
|
|
|
public function addCharacteristic(Characteristic $characteristic) |
114
|
|
|
{ |
115
|
|
|
$this->characteristics[] = $characteristic; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
} |
119
|
|
|
|
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.