1 | <?php |
||
9 | final class Ensurance |
||
10 | { |
||
11 | /** |
||
12 | * @var mixed |
||
13 | */ |
||
14 | private $value; |
||
15 | |||
16 | use EnforcementTrait; |
||
17 | |||
18 | /** |
||
19 | * Ensurance constructor. |
||
20 | * |
||
21 | * @param $value |
||
22 | */ |
||
23 | public function __construct($value) |
||
27 | |||
28 | /** |
||
29 | * @return mixed |
||
30 | */ |
||
31 | public function getValue() |
||
35 | |||
36 | /** |
||
37 | * @return ArrayEnsurance |
||
38 | */ |
||
39 | public function isArray(): ArrayEnsurance |
||
45 | |||
46 | /** |
||
47 | * @return ObjectEnsurance |
||
48 | */ |
||
49 | public function isObject(): ObjectEnsurance |
||
55 | |||
56 | /** |
||
57 | * @return ResourceEnsurance |
||
58 | */ |
||
59 | public function isResource(): ResourceEnsurance |
||
65 | |||
66 | /** |
||
67 | * @return ScalarEnsurance |
||
68 | */ |
||
69 | public function isScalar(): ScalarEnsurance |
||
75 | |||
76 | /** |
||
77 | * @return StringEnsurance |
||
78 | */ |
||
79 | public function isString(): StringEnsurance |
||
83 | |||
84 | /** |
||
85 | * @return NumericEnsurance |
||
86 | */ |
||
87 | public function isNumeric(): NumericEnsurance |
||
91 | |||
92 | /** |
||
93 | * @return BooleanEnsurance |
||
94 | */ |
||
95 | public function isBool(): BooleanEnsurance |
||
99 | |||
100 | /** |
||
101 | * @return NumericEnsurance |
||
102 | */ |
||
103 | public function isInt(): NumericEnsurance |
||
107 | |||
108 | /** |
||
109 | * @return NumericEnsurance |
||
110 | */ |
||
111 | public function isFloat(): NumericEnsurance |
||
115 | |||
116 | /** |
||
117 | * @return BooleanEnsurance |
||
118 | */ |
||
119 | public function isTrue(): BooleanEnsurance |
||
123 | |||
124 | /** |
||
125 | * @return BooleanEnsurance |
||
126 | */ |
||
127 | public function isFalse(): BooleanEnsurance |
||
131 | |||
132 | /** |
||
133 | * @return NumericEnsurance |
||
134 | */ |
||
135 | public function isPositive(): NumericEnsurance |
||
139 | |||
140 | /** |
||
141 | * @return NumericEnsurance |
||
142 | */ |
||
143 | public function isNegative(): NumericEnsurance |
||
147 | |||
148 | /** |
||
149 | * @return NumericEnsurance |
||
150 | */ |
||
151 | public function isEven(): NumericEnsurance |
||
155 | |||
156 | /** |
||
157 | * @return NumericEnsurance |
||
158 | */ |
||
159 | public function isOdd(): NumericEnsurance |
||
163 | |||
164 | /** |
||
165 | * @param string $pattern |
||
166 | * |
||
167 | * @return StringEnsurance |
||
168 | */ |
||
169 | public function match(string $pattern): StringEnsurance |
||
173 | |||
174 | /** |
||
175 | * @return Ensurance |
||
176 | */ |
||
177 | public function isNull(): self |
||
183 | |||
184 | /** |
||
185 | * @return Ensurance |
||
186 | */ |
||
187 | public function isNotNull(): self |
||
193 | |||
194 | /** |
||
195 | * @return Ensurance |
||
196 | */ |
||
197 | public function isEmpty(): self |
||
203 | |||
204 | /** |
||
205 | * @return Ensurance |
||
206 | */ |
||
207 | public function isNotEmpty(): self |
||
213 | |||
214 | /** |
||
215 | * @param $value |
||
216 | * |
||
217 | * @return Ensurance |
||
218 | */ |
||
219 | public function isEqualTo($value): self |
||
225 | |||
226 | /** |
||
227 | * @param $value |
||
228 | * |
||
229 | * @return Ensurance |
||
230 | */ |
||
231 | public function isNotEqualTo($value): self |
||
237 | |||
238 | /** |
||
239 | * @param $value |
||
240 | * |
||
241 | * @return Ensurance |
||
242 | */ |
||
243 | public function isSameAs($value): self |
||
249 | |||
250 | /** |
||
251 | * @param $value |
||
252 | * |
||
253 | * @return Ensurance |
||
254 | */ |
||
255 | public function isNotSameAs($value): self |
||
261 | |||
262 | /** |
||
263 | * @param array $data |
||
264 | * |
||
265 | * @return Ensurance |
||
266 | */ |
||
267 | public function isIn(array $data): self |
||
268 | { |
||
269 | $this->enforce(in_array($this->value, $data))->orThrow('"%s" is not a value of %s', $this->value, $data); |
||
270 | |||
271 | return $this; |
||
272 | } |
||
273 | |||
274 | /** |
||
275 | * @param array $data |
||
276 | * |
||
277 | * @return Ensurance |
||
278 | */ |
||
279 | public function isKeyOf(array $data): self |
||
285 | } |
||
286 |