|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author SignpostMarv |
|
4
|
|
|
*/ |
|
5
|
|
|
declare(strict_types=1); |
|
6
|
|
|
|
|
7
|
|
|
namespace SignpostMarv\DaftObject\SchemaOrg\DaftObjectTraits; |
|
8
|
|
|
|
|
9
|
|
|
use InvalidArgumentException; |
|
10
|
|
|
use SignpostMarv\DaftObject\SchemaOrg\Intangible\StructuredValue; |
|
11
|
|
|
use SignpostMarv\DaftObject\SchemaOrg\TypeUtilities; |
|
12
|
|
|
|
|
13
|
|
|
trait HasMinMaxValue |
|
14
|
|
|
{ |
|
15
|
|
|
use DaftObjectTrait; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @return array<int, float|int> |
|
19
|
|
|
*/ |
|
20
|
1 |
|
public function GetMaxValue() : array |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var array<int, float|int> |
|
24
|
|
|
*/ |
|
25
|
1 |
|
$out = TypeUtilities::ExpectRetrievedValueIsArray( |
|
26
|
1 |
|
'maxValue', |
|
27
|
1 |
|
$this->RetrievePropertyValueFromData('maxValue'), |
|
|
|
|
|
|
28
|
1 |
|
static::class |
|
29
|
|
|
); |
|
30
|
|
|
|
|
31
|
1 |
|
return $out; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param array<int, float|int> $value |
|
36
|
|
|
*/ |
|
37
|
1 |
|
public function SetMaxValue(array $value) : void |
|
38
|
|
|
{ |
|
39
|
1 |
|
$this->NudgePropertyWithUniqueIntegersOrFloats('maxValue', __METHOD__, $value); |
|
|
|
|
|
|
40
|
1 |
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @return array<int, float|int> |
|
44
|
|
|
*/ |
|
45
|
1 |
|
public function GetMinValue() : array |
|
46
|
|
|
{ |
|
47
|
|
|
/** |
|
48
|
|
|
* @var array<int, float|int> |
|
49
|
|
|
*/ |
|
50
|
1 |
|
$out = TypeUtilities::ExpectRetrievedValueIsArray( |
|
51
|
1 |
|
'minValue', |
|
52
|
1 |
|
$this->RetrievePropertyValueFromData('minValue'), |
|
53
|
1 |
|
static::class |
|
54
|
|
|
); |
|
55
|
|
|
|
|
56
|
1 |
|
return $out; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param array<int, float|int> $value |
|
61
|
|
|
*/ |
|
62
|
1 |
|
public function SetMinValue(array $value) : void |
|
63
|
|
|
{ |
|
64
|
1 |
|
$this->NudgePropertyWithUniqueIntegersOrFloats('minValue', __METHOD__, $value); |
|
65
|
1 |
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @return array<int, bool|string|int|float|StructuredValue> |
|
69
|
|
|
*/ |
|
70
|
1 |
|
public function GetValue() : array |
|
71
|
|
|
{ |
|
72
|
|
|
/** |
|
73
|
|
|
* @var array<int, string> |
|
74
|
|
|
*/ |
|
75
|
1 |
|
$out = TypeUtilities::ExpectRetrievedValueIsArray( |
|
76
|
1 |
|
'value', |
|
77
|
1 |
|
$this->RetrievePropertyValueFromData('value'), |
|
78
|
1 |
|
static::class |
|
79
|
|
|
); |
|
80
|
|
|
|
|
81
|
1 |
|
return $out; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @param array<int, bool|string|int|float|StructuredValue> $value |
|
86
|
|
|
*/ |
|
87
|
1 |
|
public function SetValue(array $value) : void |
|
88
|
|
|
{ |
|
89
|
1 |
|
$initialCount = count($value); |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @var array<int, bool|string|int|float|StructuredValue> |
|
93
|
|
|
*/ |
|
94
|
1 |
|
$value = array_filter( |
|
95
|
1 |
|
$value, |
|
96
|
|
|
/** |
|
97
|
|
|
* @param mixed $maybe |
|
98
|
|
|
*/ |
|
99
|
|
|
function ($maybe) : bool { |
|
100
|
|
|
return |
|
101
|
|
|
is_bool($maybe) || |
|
102
|
|
|
is_string($maybe) || |
|
103
|
|
|
is_float($maybe) || |
|
104
|
|
|
is_int($maybe) || |
|
105
|
|
|
($maybe instanceof StructuredValue); |
|
106
|
1 |
|
} |
|
107
|
|
|
); |
|
108
|
|
|
|
|
109
|
1 |
|
if (count($value) !== $initialCount) { |
|
110
|
|
|
throw new InvalidArgumentException( |
|
111
|
|
|
'Argument 1 passed to ' . |
|
112
|
|
|
__METHOD__ . |
|
113
|
|
|
' must be an array of any combination of booleans, strings, floats, ints, and ' . |
|
114
|
|
|
StructuredValue::class . |
|
115
|
|
|
'!' |
|
116
|
|
|
); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
1 |
|
$this->NudgePropertyValue('value', $value); |
|
120
|
1 |
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|