1
|
|
|
<?php |
2
|
|
|
namespace Bpost\BpostApiClient\Bpost\Order; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* bPost Line class |
6
|
|
|
* |
7
|
|
|
* @author Tijs Verkoyen <[email protected]> |
8
|
|
|
*/ |
9
|
|
|
class Line |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var string |
13
|
|
|
*/ |
14
|
|
|
private $text; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var int |
18
|
|
|
*/ |
19
|
|
|
private $numberOfItems; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param int $nbOfItems |
23
|
|
|
*/ |
24
|
3 |
|
public function setNumberOfItems($nbOfItems) |
25
|
|
|
{ |
26
|
3 |
|
$this->numberOfItems = $nbOfItems; |
27
|
3 |
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @return int |
31
|
|
|
*/ |
32
|
2 |
|
public function getNumberOfItems() |
33
|
|
|
{ |
34
|
2 |
|
return $this->numberOfItems; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param string $text |
39
|
|
|
*/ |
40
|
3 |
|
public function setText($text) |
41
|
|
|
{ |
42
|
3 |
|
$this->text = $text; |
43
|
3 |
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return string |
47
|
|
|
*/ |
48
|
2 |
|
public function getText() |
49
|
|
|
{ |
50
|
2 |
|
return $this->text; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param string $text |
|
|
|
|
55
|
|
|
* @param int $numberOfItems |
|
|
|
|
56
|
|
|
*/ |
57
|
3 |
|
public function __construct($text = null, $numberOfItems = null) |
58
|
|
|
{ |
59
|
3 |
|
if ($text != null) { |
|
|
|
|
60
|
2 |
|
$this->setText($text); |
61
|
2 |
|
} |
62
|
3 |
|
if ($numberOfItems != null) { |
|
|
|
|
63
|
2 |
|
$this->setNumberOfItems($numberOfItems); |
64
|
2 |
|
} |
65
|
3 |
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Return the object as an array for usage in the XML |
69
|
|
|
* |
70
|
|
|
* @param \DomDocument $document |
71
|
|
|
* @param string $prefix |
|
|
|
|
72
|
|
|
* @return \DOMElement |
73
|
|
|
*/ |
74
|
2 |
|
public function toXML(\DomDocument $document, $prefix = null) |
75
|
|
|
{ |
76
|
2 |
|
$tagName = 'orderLine'; |
77
|
2 |
|
if ($prefix !== null) { |
78
|
1 |
|
$tagName = $prefix . ':' . $tagName; |
79
|
1 |
|
} |
80
|
|
|
|
81
|
2 |
|
$line = $document->createElement($tagName); |
82
|
|
|
|
83
|
2 |
View Code Duplication |
if ($this->getText() !== null) { |
|
|
|
|
84
|
2 |
|
$tagName = 'text'; |
85
|
2 |
|
if ($prefix !== null) { |
86
|
1 |
|
$tagName = $prefix . ':' . $tagName; |
87
|
1 |
|
} |
88
|
2 |
|
$line->appendChild( |
89
|
2 |
|
$document->createElement( |
90
|
2 |
|
$tagName, |
91
|
2 |
|
$this->getText() |
92
|
2 |
|
) |
93
|
2 |
|
); |
94
|
2 |
|
} |
95
|
2 |
|
if ($this->getNumberOfItems() !== null) { |
96
|
2 |
|
$tagName = 'nbOfItems'; |
97
|
2 |
|
if ($prefix !== null) { |
98
|
1 |
|
$tagName = $prefix . ':' . $tagName; |
99
|
1 |
|
} |
100
|
2 |
|
$line->appendChild( |
101
|
2 |
|
$document->createElement( |
102
|
2 |
|
$tagName, |
103
|
2 |
|
$this->getNumberOfItems() |
104
|
2 |
|
) |
105
|
2 |
|
); |
106
|
2 |
|
} |
107
|
|
|
|
108
|
2 |
|
return $line; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @param \SimpleXMLElement $xml |
113
|
|
|
* @return Line |
114
|
|
|
*/ |
115
|
1 |
|
public static function createFromXML(\SimpleXMLElement $xml) |
116
|
|
|
{ |
117
|
1 |
|
$line = new Line(); |
118
|
1 |
|
if (isset($xml->text) && $xml->text != '') { |
119
|
1 |
|
$line->setText((string) $xml->text); |
120
|
1 |
|
} |
121
|
1 |
|
if (isset($xml->nbOfItems) && $xml->nbOfItems != '') { |
122
|
1 |
|
$line->setNumberOfItems((int) $xml->nbOfItems); |
123
|
1 |
|
} |
124
|
|
|
|
125
|
1 |
|
return $line; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.