1
|
|
|
<?php |
2
|
|
|
namespace AlgoWeb\xsdTypes\Facets; |
3
|
|
|
|
4
|
|
|
trait MinMaxTrait |
5
|
|
|
{ |
6
|
|
|
/** |
7
|
|
|
* @Exclude |
8
|
|
|
* @var int|float|\DateTime|\AlgoWeb\xsdTypes\AxillaryClasses\Calender Specifies the lower bounds for numeric values |
9
|
|
|
* (the value must be greater than or equal to |
10
|
|
|
* this value) |
11
|
|
|
*/ |
12
|
|
|
private $minInclusive = null; |
13
|
|
|
/** |
14
|
|
|
* @Exclude |
15
|
|
|
* @var int|float|\DateTime|\AlgoWeb\xsdTypes\AxillaryClasses\Calender Specifies the upper bounds for numeric values |
16
|
|
|
* (the value must be less than or equal to this |
17
|
|
|
* value) |
18
|
|
|
*/ |
19
|
|
|
private $maxInclusive = null; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @Exclude |
23
|
|
|
* @var int|float|\DateTime|\AlgoWeb\xsdTypes\AxillaryClasses\Calender Specifies the upper bounds for numeric values |
24
|
|
|
* (the value must be less than or equal to this |
25
|
|
|
* value) |
26
|
|
|
*/ |
27
|
|
|
private $minExclusive = null; |
28
|
|
|
/** |
29
|
|
|
* @Exclude |
30
|
|
|
* @var int|float|\DateTime|\AlgoWeb\xsdTypes\AxillaryClasses\Calender Specifies the upper bounds for numeric values |
31
|
|
|
* (the value must be less than or equal to this |
32
|
|
|
* value) |
33
|
|
|
*/ |
34
|
|
|
private $maxExclusive = null; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param int|float|\DateTime|\AlgoWeb\xsdTypes\AxillaryClasses\Calender $newMax Specifies the upper bounds for numeric |
|
|
|
|
38
|
|
|
* values (the value must be less than this |
|
|
|
|
39
|
|
|
* value) |
40
|
|
|
*/ |
41
|
|
|
public function setMaxExclusive($newMax) |
42
|
|
|
{ |
43
|
|
|
$this->maxExclusive = $newMax; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param int|float|\DateTime|\DateInterval $newMax Specifies the upper bounds for numeric values |
48
|
|
|
* (the value must be less than or equal to this value) |
49
|
|
|
*/ |
50
|
|
|
public function setMaxInclusive($newMax) |
51
|
|
|
{ |
52
|
|
|
$this->maxInclusive = $newMax; |
|
|
|
|
53
|
|
|
} |
54
|
|
|
/** |
55
|
|
|
* @param int|float|\DateTime|\DateInterval $newMin Specifies the lower bounds for numeric values |
56
|
|
|
* (the value must be greater than this value) |
57
|
|
|
*/ |
58
|
|
|
public function setMinExclusive($newMin) |
59
|
|
|
{ |
60
|
|
|
$this->minExclusive = $newMin; |
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param int|float|\DateTime|\DateInterval $newMin Specifies the lower bounds for numeric values |
65
|
|
|
* (the value must be greater than or equal to this value) |
66
|
|
|
*/ |
67
|
|
|
public function setMinInclusive($newMin) |
68
|
|
|
{ |
69
|
|
|
$this->minInclusive = $newMin; |
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function checkMinMax($value) |
73
|
|
|
{ |
74
|
|
|
if (null !== $this->minInclusive) { |
75
|
|
|
$this->checkMin($value); |
76
|
|
|
} |
77
|
|
|
if (null !== $this->maxInclusive) { |
78
|
|
|
$this->checkMax($value); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
private function checkMin($value) |
83
|
|
|
{ |
84
|
|
|
if ($value < $this->minInclusive) { |
85
|
|
|
throw new \InvalidArgumentException('Value less than allowed min value ' . get_class($this)); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
private function checkMax($value) |
90
|
|
|
{ |
91
|
|
|
if ($value > $this->maxInclusive) { |
92
|
|
|
throw new \InvalidArgumentException('Value greater than allowed max value ' . get_class($this)); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.