|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bpost\BpostApiClient\Bpost\Order\Box\OpeningHour; |
|
4
|
|
|
|
|
5
|
|
|
use Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidValueException; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* bPost Day class |
|
9
|
|
|
* |
|
10
|
|
|
* @author Tijs Verkoyen <[email protected]> |
|
11
|
|
|
* @version 3.0.0 |
|
12
|
|
|
* @copyright Copyright (c), Tijs Verkoyen. All rights reserved. |
|
13
|
|
|
* @license BSD License |
|
14
|
|
|
*/ |
|
15
|
|
|
class Day |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
const DAY_MONDAY = 'Monday'; |
|
19
|
|
|
const DAY_TUESDAY = 'Tuesday'; |
|
20
|
|
|
const DAY_WEDNESDAY = 'Wednesday'; |
|
21
|
|
|
const DAY_THURSDAY = 'Thursday'; |
|
22
|
|
|
const DAY_FRIDAY = 'Friday'; |
|
23
|
|
|
const DAY_SATURDAY = 'Saturday'; |
|
24
|
|
|
const DAY_SUNDAY = 'Sunday'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
private $day; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var string |
|
33
|
|
|
*/ |
|
34
|
|
|
private $value; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param string $day |
|
38
|
|
|
* @throws BpostInvalidValueException |
|
39
|
|
|
*/ |
|
40
|
4 |
|
public function setDay($day) |
|
41
|
|
|
{ |
|
42
|
4 |
|
if (!in_array($day, self::getPossibleDayValues())) { |
|
43
|
1 |
|
throw new BpostInvalidValueException('day', $day, self::getPossibleDayValues()); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
3 |
|
$this->day = $day; |
|
47
|
3 |
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @return string |
|
51
|
|
|
*/ |
|
52
|
2 |
|
public function getDay() |
|
53
|
|
|
{ |
|
54
|
2 |
|
return $this->day; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @return array |
|
59
|
|
|
*/ |
|
60
|
4 |
|
public static function getPossibleDayValues() |
|
61
|
|
|
{ |
|
62
|
|
|
return array( |
|
63
|
4 |
|
self::DAY_MONDAY, |
|
64
|
4 |
|
self::DAY_TUESDAY, |
|
65
|
4 |
|
self::DAY_WEDNESDAY, |
|
66
|
4 |
|
self::DAY_THURSDAY, |
|
67
|
4 |
|
self::DAY_FRIDAY, |
|
68
|
4 |
|
self::DAY_SATURDAY, |
|
69
|
4 |
|
self::DAY_SUNDAY, |
|
70
|
4 |
|
); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @param string $value |
|
75
|
|
|
*/ |
|
76
|
3 |
|
public function setValue($value) |
|
77
|
|
|
{ |
|
78
|
3 |
|
$this->value = $value; |
|
79
|
3 |
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return string |
|
83
|
|
|
*/ |
|
84
|
3 |
|
public function getValue() |
|
85
|
|
|
{ |
|
86
|
3 |
|
return $this->value; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @param string $day |
|
91
|
|
|
* @param string $value |
|
92
|
|
|
* |
|
93
|
|
|
* @throws BpostInvalidValueException |
|
94
|
|
|
*/ |
|
95
|
4 |
|
public function __construct($day, $value) |
|
96
|
|
|
{ |
|
97
|
4 |
|
$this->setDay($day); |
|
98
|
3 |
|
$this->setValue($value); |
|
99
|
3 |
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Return the object as an array for usage in the XML |
|
103
|
|
|
* |
|
104
|
|
|
* @param \DomDocument $document |
|
105
|
|
|
* @param string $prefix |
|
|
|
|
|
|
106
|
|
|
* @return \DomElement |
|
107
|
|
|
*/ |
|
108
|
2 |
|
public function toXML(\DOMDocument $document, $prefix = null) |
|
109
|
|
|
{ |
|
110
|
2 |
|
$tagName = $this->getDay(); |
|
111
|
2 |
|
if ($prefix !== null) { |
|
112
|
1 |
|
$tagName = $prefix . ':' . $tagName; |
|
113
|
1 |
|
} |
|
114
|
|
|
|
|
115
|
2 |
|
return $document->createElement($tagName, $this->getValue()); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
This check looks for
@paramannotations 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.