Passed
Pull Request — master (#1)
by Tim
01:47
created

Assert::__callStatic()   A

Complexity

Conditions 6
Paths 10

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 6
eloc 13
c 3
b 0
f 0
nc 10
nop 2
dl 0
loc 20
rs 9.2222
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\Assert;
6
7
use BadMethodCallException;
8
use DateTime;
9
use DateTimeImmutable;
10
use InvalidArgumentException;
11
use Throwable;
12
use Webmozart\Assert\Assert as Webmozart;
13
14
use function array_map;
15
use function array_pop;
16
use function base64_decode;
17
use function base64_encode;
18
use function call_user_func_array;
19
use function end;
20
use function filter_var;
21
use function get_class;
22
use function implode;
23
use function in_array;
24
use function is_string;
25
use function is_object;
26
use function is_resource;
27
use function is_subclass_of;
28
use function method_exists;
29
use function sprintf;
30
31
/**
32
 * Webmozart\Assert wrapper class
33
 *
34
 * @package simplesamlphp/assert
35
 *
36
 * @method static void string(mixed $value, string $message = '', Throwable $exception = null)
37
 * @method static void stringNotEmpty(mixed $value, string $message = '', Throwable $exception = null)
38
 * @method static void integer(mixed $value, string $message = '', Throwable $exception = null)
39
 * @method static void integerish(mixed $value, string $message = '', Throwable $exception = null)
40
 * @method static void positiveInteger(mixed $value, string $message = '', Throwable $exception = null)
41
 * @method static void float(mixed $value, string $message = '', Throwable $exception = null)
42
 * @method static void numeric(mixed $value, string $message = '', Throwable $exception = null)
43
 * @method static void natural(mixed $value, string $message = '', Throwable $exception = null)
44
 * @method static void boolean(mixed $value, string $message = '', Throwable $exception = null)
45
 * @method static void scalar(mixed $value, string $message = '', Throwable $exception = null)
46
 * @method static void object(mixed $value, string $message = '', Throwable $exception = null)
47
 * @method static void resource(mixed $value, string|null $type, string $message = '', Throwable $exception = null)
48
 * @method static void isCallable(mixed $value, string $message = '', Throwable $exception = null)
49
 * @method static void isArray(mixed $value, string $message = '', Throwable $exception = null)
50
 * @method static void isTraversable(mixed $value, string $message = '', Throwable $exception = null)
51
 * @method static void isArrayAccessible(mixed $value, string $message = '', Throwable $exception = null)
52
 * @method static void isCountable(mixed $value, string $message = '', Throwable $exception = null)
53
 * @method static void isIterable(mixed $value, string $message = '', Throwable $exception = null)
54
 * @method static void isInstanceOf(mixed $value, string|object $class, string $message = '', Throwable $exception = null)
55
 * @method static void notInstanceOf(mixed $value, string|object $class, string $message = '', Throwable $exception = null)
56
 * @method static void isInstanceOfAny(mixed $value, array<object|string> $classes, string $message = '', Throwable $exception = null)
57
 * @method static void isAOf(string|object $value, string $class, string $message = '', Throwable $exception = null)
58
 * @method static void isNotA(string|object $value, string $class, string $message = '', Throwable $exception = null)
59
 * @method static void isAnyOf(string|object $value, string[] $classes, string $message = '', Throwable $exception = null)
60
 * @method static void isEmpty(mixed $value, string $message = '', Throwable $exception = null)
61
 * @method static void notEmpty(mixed $value, string $message = '', Throwable $exception = null)
62
 * @method static void null(mixed $value, string $message = '', Throwable $exception = null)
63
 * @method static void notNull(mixed $value, string $message = '', Throwable $exception = null)
64
 * @method static void true(mixed $value, string $message = '', Throwable $exception = null)
65
 * @method static void false(mixed $value, string $message = '', Throwable $exception = null)
66
 * @method static void notFalse(mixed $value, string $message = '', Throwable $exception = null)
67
 * @method static void ip(mixed $value, string $message = '', Throwable $exception = null)
68
 * @method static void ipv4(mixed $value, string $message = '', Throwable $exception = null)
69
 * @method static void ipv6(mixed $value, string $message = '', Throwable $exception = null)
70
 * @method static void email(mixed $value, string $message = '', Throwable $exception = null)
71
 * @method static void uniqueValues(array $values, string $message = '', Throwable $exception = null)
72
 * @method static void eq(mixed $value, mixed $expect, string $message = '', Throwable $exception = null)
73
 * @method static void notEq(mixed $value, mixed $expect, string $message = '', Throwable $exception = null)
74
 * @method static void same(mixed $value, mixed $expect, string $message = '', Throwable $exception = null)
75
 * @method static void notSame(mixed $value, mixed $expect, string $message = '', Throwable $exception = null)
76
 * @method static void greaterThan(mixed $value, mixed $limit, string $message = '', Throwable $exception = null)
77
 * @method static void greaterThanEq(mixed $value, mixed $limit, string $message = '', Throwable $exception = null)
78
 * @method static void lessThan(mixed $value, mixed $limit, string $message = '', Throwable $exception = null)
79
 * @method static void lessThanEq(mixed $value, mixed $limit, string $message = '', Throwable $exception = null)
80
 * @method static void range(mixed $value, mixed $min, mixed $max, string $message = '', Throwable $exception = null)
81
 * @method static void oneOf(mixed $value, array $values, string $message = '', Throwable $exception = null)
82
 * @method static void inArray(mixed $value, mixed $values, string $message = '', Throwable $exception = null)
83
 * @method static void contains(string $value, string $subString, string $message = '', Throwable $exception = null)
84
 * @method static void notContains(string $value, string $subString, string $message = '', Throwable $exception = null)
85
 * @method static void notWhitespaceOnly($value, string $message = '', Throwable $exception = null)
86
 * @method static void startsWith(string $value, string $prefix, string $message = '', Throwable $exception = null)
87
 * @method static void notStartsWith(string $value, string $prefix, string $message = '', Throwable $exception = null)
88
 * @method static void startsWithLetter(mixed $value, string $message = '', Throwable $exception = null)
89
 * @method static void endsWith(string $value, string $suffix, string $message = '', Throwable $exception = null)
90
 * @method static void notEndsWith(string $value, string $suffix, string $message = '', Throwable $exception = null)
91
 * @method static void regex(string $value, string $pattern, string $message = '', Throwable $exception = null)
92
 * @method static void notRegex(string $value, string $pattern, string $message = '', Throwable $exception = null)
93
 * @method static void unicodeLetters(mixed $value, string $message = '', Throwable $exception = null)
94
 * @method static void alpha(mixed $value, string $message = '', Throwable $exception = null)
95
 * @method static void digits(string $value, string $message = '', Throwable $exception = null)
96
 * @method static void alnum(string $value, string $message = '', Throwable $exception = null)
97
 * @method static void lower(string $value, string $message = '', Throwable $exception = null)
98
 * @method static void upper(string $value, string $message = '', Throwable $exception = null)
99
 * @method static void length(string $value, int $length, string $message = '', Throwable $exception = null)
100
 * @method static void minLength(string $value, int|float $min, string $message = '', Throwable $exception = null)
101
 * @method static void maxLength(string $value, int|float $max, string $message = '', Throwable $exception = null)
102
 * @method static void lengthBetween(string $value, int|float $min, int|float $max, string $message = '', Throwable $exception = null)
103
 * @method static void fileExists(mixed $value, string $message = '', Throwable $exception = null)
104
 * @method static void file(mixed $value, string $message = '', Throwable $exception = null)
105
 * @method static void directory(mixed $value, string $message = '', Throwable $exception = null)
106
 * @method static void readable(string $value, string $message = '', Throwable $exception = null)
107
 * @method static void writable(string $value, string $message = '', Throwable $exception = null)
108
 * @method static void classExists(mixed $value, string $message = '', Throwable $exception = null)
109
 * @method static void subclassOf(mixed $value, string|object $class, string $message = '', Throwable $exception = null)
110
 * @method static void interfaceExists(mixed $value, string $message = '', Throwable $exception = null)
111
 * @method static void implementsInterface(mixed $value, mixed $interface, string $message = '', Throwable $exception = null)
112
 * @method static void propertyExists(string|object $classOrObject, mixed $property, string $message = '', Throwable $exception = null)
113
 * @method static void propertyNotExists(string|object $classOrObject, mixed $property, string $message = '', Throwable $exception = null)
114
 * @method static void methodExists(string|object $classOrObject, mixed $method, string $message = '', Throwable $exception = null)
115
 * @method static void methodNotExists(string|object $classOrObject, mixed $method, string $message = '', Throwable $exception = null)
116
 * @method static void keyExists(array $array, string|int $key, string $message = '', Throwable $exception = null)
117
 * @method static void keyNotExists(array $array, string|int $key, string $message = '', Throwable $exception = null)
118
 * @method static void validArrayKey($value, string $message = '', Throwable $exception = null)
119
 * @method static void count(Countable|array $array, int $number, string $message = '', Throwable $exception = null)
120
 * @method static void minCount(Countable|array $array, int|float $min, string $message = '', Throwable $exception = null)
121
 * @method static void maxCount(Countable|array $array, int|float $max, string $message = '', Throwable $exception = null)
122
 * @method static void countBetween(Countable|array $array, int|float $min, int|float $max, string $message = '', Throwable $exception = null)
123
 * @method static void isList(mixed $array, string $message = '', Throwable $exception = null)
124
 * @method static void isNonEmptyList(mixed $array, string $message = '', Throwable $exception = null)
125
 * @method static void isMap(mixed $array, string $message = '', Throwable $exception = null)
126
 * @method static void isNonEmptyMap(mixed $array, string $message = '', Throwable $exception = null)
127
 * @method static void uid(string $value, string $message = '', Throwable $exception = null)
128
 *
129
 * @method static string valueToString(mixed $value);
130
 * @method static void throws(Closure $expression, string $class = 'Exception', string $message = '', Throwable $exception = null)
131
 *
132
 * @method static void nullOrString(mixed $value, string $message = '', Throwable $exception = null)
133
 * @method static void allString(mixed $value, string $message = '', Throwable $exception = null)
134
 * @method static void nullOrStringNotEmpty(mixed $value, string $message = '', Throwable $exception = null)
135
 * @method static void allOrStringNotEmpty(mixed $value, string $message = '', Throwable $exception = null)
136
 * @method static void nullOrInteger(mixed $value, string $message = '', Throwable $exception = null)
137
 * @method static void allInteger(mixed $value, string $message = '', Throwable $exception = null)
138
 * @method static void nullOrIntegerish(mixed $value, string $message = '', Throwable $exception = null)
139
 * @method static void allIntegerish(mixed $value, string $message = '', Throwable $exception = null)
140
 * @method static void nullOrPositiveInteger(mixed $value, string $message = '', Throwable $exception = null)
141
 * @method static void allPositiveInteger(mixed $value, string $message = '', Throwable $exception = null)
142
 * @method static void nullOrFloat(mixed $value, string $message = '', Throwable $exception = null)
143
 * @method static void allFloat(mixed $value, string $message = '', Throwable $exception = null)
144
 * @method static void nullOrNumeric(mixed $value, string $message = '', Throwable $exception = null)
145
 * @method static void allNumeric(mixed $value, string $message = '', Throwable $exception = null)
146
 * @method static void nullOrNatural(mixed $value, string $message = '', Throwable $exception = null)
147
 * @method static void allNatural(mixed $value, string $message = '', Throwable $exception = null)
148
 * @method static void nullOrBoolean(mixed $value, string $message = '', Throwable $exception = null)
149
 * @method static void allBoolean(mixed $value, string $message = '', Throwable $exception = null)
150
 * @method static void nullOrScalar(mixed $value, string $message = '', Throwable $exception = null)
151
 * @method static void allScalar(mixed $value, string $message = '', Throwable $exception = null)
152
 * @method static void nullOrObject(mixed $value, string $message = '', Throwable $exception = null)
153
 * @method static void allObject(mixed $value, string $message = '', Throwable $exception = null)
154
 * @method static void nullOrResource(mixed $value, string|null $type, string $message = '', Throwable $exception = null)
155
 * @method static void allResource(mixed $value, string|null $type, string $message = '', Throwable $exception = null)
156
 * @method static void nullOrIsCallable(mixed $value, string $message = '', Throwable $exception = null)
157
 * @method static void allIsCallable(mixed $value, string $message = '', Throwable $exception = null)
158
 * @method static void nullOrIsArray(mixed $value, string $message = '', Throwable $exception = null)
159
 * @method static void allIsArray(mixed $value, string $message = '', Throwable $exception = null)
160
 * @method static void nullOrIsTraversable(mixed $value, string $message = '', Throwable $exception = null)
161
 * @method static void allIsTraversable(mixed $value, string $message = '', Throwable $exception = null)
162
 * @method static void nullOrIsArrayAccessible(mixed $value, string $message = '', Throwable $exception = null)
163
 * @method static void allIsArrayAccessible(mixed $value, string $message = '', Throwable $exception = null)
164
 * @method static void nullOrIsCountable(mixed $value, string $message = '', Throwable $exception = null)
165
 * @method static void allIsCountable(mixed $value, string $message = '', Throwable $exception = null)
166
 * @method static void nullOrIsIterable(mixed $value, string $message = '', Throwable $exception = null)
167
 * @method static void allIsIterable(mixed $value, string $message = '', Throwable $exception = null)
168
 * @method static void nullOrIsInstanceOf(mixed $value, string|object $class, string $message = '', Throwable $exception = null)
169
 * @method static void allIsInstanceOf(mixed $value, string|object $class, string $message = '', Throwable $exception = null)
170
 * @method static void nullOrNotInstanceOf(mixed $value, string|object $class, string $message = '', Throwable $exception = null)
171
 * @method static void allNotInstanceOf(mixed $value, string|object $class, string $message = '', Throwable $exception = null)
172
 * @method static void nullOrIsInstanceOfAny(mixed $value, array<object|string> $classes, string $message = '', Throwable $exception = null)
173
 * @method static void allIsInstanceOfAny(mixed $value, array<object|string> $classes, string $message = '', Throwable $exception = null)
174
 * @method static void nullOrIsAOf(object|string|null $value, string $class, string $message = '', Throwable $exception = null)
175
 * @method static void allIsAOf(object|string|null $value, string $class, string $message = '', Throwable $exception = null)
176
 * @method static void nullOrIsNotA(object|string|null $value, string $class, string $message = '', Throwable $exception = null)
177
 * @method static void allIsNotA(iterable<object|string> $value, string $class, string $message = '', Throwable $exception = null)
178
 * @method static void nullOrIsAnyOf(object|string|null $value, string[] $classes, string $message = '', Throwable $exception = null)
179
 * @method static void allIsAnyOf(iterable<object|string> $value, string[] $classes, string $message = '', Throwable $exception = null)
180
 * @method static void nullOrIsEmpty(mixed $value, string $message = '', Throwable $exception = null)
181
 * @method static void allIsEmpty(mixed $value, string $message = '', Throwable $exception = null)
182
 * @method static void nullOrNotEmpty(mixed $value, string $message = '', Throwable $exception = null)
183
 * @method static void allNotEmpty(mixed $value, string $message = '', Throwable $exception = null)
184
 * @method static void allNull(mixed $value, string $message = '', Throwable $exception = null)
185
 * @method static void allNotNull(mixed $value, string $message = '', Throwable $exception = null)
186
 * @method static void nullOrTrue(mixed $value, string $message = '', Throwable $exception = null)
187
 * @method static void allTrue(mixed $value, string $message = '', Throwable $exception = null)
188
 * @method static void nullOrFalse(mixed $value, string $message = '', Throwable $exception = null)
189
 * @method static void allFalse(mixed $value, string $message = '', Throwable $exception = null)
190
 * @method static void nullOrNotFalse(mixed $value, string $message = '', Throwable $exception = null)
191
 * @method static void allNotFalse(mixed $value, string $message = '', Throwable $exception = null)
192
 * @method static void nullOrIp(mixed $value, string $message = '', Throwable $exception = null)
193
 * @method static void allIp(mixed $value, string $message = '', Throwable $exception = null)
194
 * @method static void nullOrIpv4(mixed $value, string $message = '', Throwable $exception = null)
195
 * @method static void allIpv4(mixed $value, string $message = '', Throwable $exception = null)
196
 * @method static void nullOrIpv6(mixed $value, string $message = '', Throwable $exception = null)
197
 * @method static void allIpv6(mixed $value, string $message = '', Throwable $exception = null)
198
 * @method static void nullOrEmail(mixed $value, string $message = '', Throwable $exception = null)
199
 * @method static void allEmail(mixed $value, string $message = '', Throwable $exception = null)
200
 * @method static void nullOrUniqueValues(array|null $values, string $message = '', Throwable $exception = null)
201
 * @method static void allUniqueValues(iterable<array> $values, string $message = '', Throwable $exception = null)
202
 * @method static void nullOrEq(mixed $value, mixed $expect, string $message = '', Throwable $exception = null)
203
 * @method static void allEq(mixed $value, mixed $expect, string $message = '', Throwable $exception = null)
204
 * @method static void nullOrNotEq(mixed $value, mixed $expect, string $message = '', Throwable $exception = null)
205
 * @method static void allNotEq(mixed $value, mixed $expect, string $message = '', Throwable $exception = null)
206
 * @method static void nullOrSame(mixed $value, mixed $expect, string $message = '', Throwable $exception = null)
207
 * @method static void allSame(mixed $value, mixed $expect, string $message = '', Throwable $exception = null)
208
 * @method static void nullOrNotSame(mixed $value, mixed $expect, string $message = '', Throwable $exception = null)
209
 * @method static void allNotSame(mixed $value, mixed $expect, string $message = '', Throwable $exception = null)
210
 * @method static void nullOrGreaterThan(mixed $value, mixed $limit, string $message = '', Throwable $exception = null)
211
 * @method static void allGreaterThan(mixed $value, mixed $limit, string $message = '', Throwable $exception = null)
212
 * @method static void nullOrGreaterThanEq(mixed $value, mixed $limit, string $message = '', Throwable $exception = null)
213
 * @method static void allGreaterThanEq(mixed $value, mixed $limit, string $message = '', Throwable $exception = null)
214
 * @method static void nullOrLessThan(mixed $value, mixed $limit, string $message = '', Throwable $exception = null)
215
 * @method static void allLessThan(mixed $value, mixed $limit, string $message = '', Throwable $exception = null)
216
 * @method static void nullOrLessThanEq(mixed $value, mixed $limit, string $message = '', Throwable $exception = null)
217
 * @method static void allLessThanEq(mixed $value, mixed $limit, string $message = '', Throwable $exception = null)
218
 * @method static void nullOrRange(mixed $value, mixed $min, mixed $max, string $message = '', Throwable $exception = null)
219
 * @method static void allRange(mixed $value, mixed $min, mixed $max, string $message = '', Throwable $exception = null)
220
 * @method static void nullOrOneOf(mixed $value, array $values, string $message = '', Throwable $exception = null)
221
 * @method static void allOneOf(mixed $value, array $values, string $message = '', Throwable $exception = null)
222
 * @method static void nullOrInArray(mixed $value, array $values, string $message = '', Throwable $exception = null)
223
 * @method static void allInArray(mixed $value, array $values, string $message = '', Throwable $exception = null)
224
 * @method static void nullOrContains(string|null $value, string $subString, string $message = '', Throwable $exception = null)
225
 * @method static void allContains(iterable<string> $value, string $subString, string $message = '', Throwable $exception = null)
226
 * @method static void nullOrNotContains(string|null $value, string $subString, string $message = '', Throwable $exception = null)
227
 * @method static void allNotContains(iterable<string> $value, string $subString, string $message = '', Throwable $exception = null)
228
 * @method static void nullOrWhitespaceOnly(string|null $value, string $message = '', Throwable $exception = null)
229
 * @method static void allWhitespaceOnly(iterable<string> $value, string $message = '', Throwable $exception = null)
230
 * @method static void nullOrStartsWith(string|null $value, string $prefix, string $message = '', Throwable $exception = null)
231
 * @method static void allStartsWith(iterable<string> $value, string $prefix, string $message = '', Throwable $exception = null)
232
 * @method static void nullOrNotStartsWith(string|null $value, string $prefix, string $message = '', Throwable $exception = null)
233
 * @method static void allNotStartsWith(iterable<string> $value, string $prefix, string $message = '', Throwable $exception = null)
234
 * @method static void nullOrStartsWithLetter(mixed $value, string $message = '', Throwable $exception = null)
235
 * @method static void allStartsWithLetter(mixed $value, string $message = '', Throwable $exception = null)
236
 * @method static void nullOrEndsWith(string|null $value, string $suffix, string $message = '', Throwable $exception = null)
237
 * @method static void allEndsWith(iterable<string> $value, string $suffix, string $message = '', Throwable $exception = null)
238
 * @method static void nullOrNotEndsWith(string|null $value, string $suffix, string $message = '', Throwable $exception = null)
239
 * @method static void allNotEndsWith(iterable<string> $value, string $suffix, string $message = '', Throwable $exception = null)
240
 * @method static void nullOrRegex(string|null $value, string $prefix, string $message = '', Throwable $exception = null)
241
 * @method static void allRegEx(iterable<string> $value, string $prefix, string $message = '', Throwable $exception = null)
242
 * @method static void nullOrNotRegex(string|null $value, string $prefix, string $message = '', Throwable $exception = null)
243
 * @method static void allNotRegEx(iterable<string> $value, string $prefix, string $message = '', Throwable $exception = null)
244
 * @method static void nullOrUnicodeLetters(mixed $value, string $message = '', Throwable $exception = null)
245
 * @method static void allUnicodeLetters(mixed $value, string $message = '', Throwable $exception = null)
246
 * @method static void nullOrAlpha(mixed $value, string $message = '', Throwable $exception = null)
247
 * @method static void allAlpha(mixed $value, string $message = '', Throwable $exception = null)
248
 * @method static void nullOrDigits(string|null $value, string $message = '', Throwable $exception = null)
249
 * @method static void allDigits(iterable<string> $value, string $message = '', Throwable $exception = null)
250
 * @method static void nullOrAlnum(string|null $value, string $message = '', Throwable $exception = null)
251
 * @method static void allAlnum(iterable<string> $value, string $message = '', Throwable $exception = null)
252
 * @method static void nullOrLower(string|null $value, string $message = '', Throwable $exception = null)
253
 * @method static void allLower(iterable<string> $value, string $message = '', Throwable $exception = null)
254
 * @method static void nullOrUpper(string|null $value, string $message = '', Throwable $exception = null)
255
 * @method static void allUpper(iterable<string> $value, string $message = '', Throwable $exception = null)
256
 * @method static void nullOrLength(string|null $value, int $length, string $message = '', Throwable $exception = null)
257
 * @method static void allLength(iterable<string> $value, int $length, string $message = '', Throwable $exception = null)
258
 * @method static void nullOrMinLength(string|null $value, int|float $min, string $message = '', Throwable $exception = null)
259
 * @method static void allMinLength(iterable<string> $value, int|float $min, string $message = '', Throwable $exception = null)
260
 * @method static void nullOrMaxLength(string|null $value, int|float $max, string $message = '', Throwable $exception = null)
261
 * @method static void allMaxLength(iterable<string> $value, int|float $max, string $message = '', Throwable $exception = null)
262
 * @method static void nullOrLengthBetween(string|null $value, int|float $min, int|float $max, string $message = '', Throwable $exception = null)
263
 * @method static void allLengthBetween(iterable<string> $value, int|float $min, int|float $max, string $message = '', Throwable $exception = null)
264
 * @method static void nullOrFileExists(mixed $value, string $message = '', Throwable $exception = null)
265
 * @method static void allFileExists(mixed $value, string $message = '', Throwable $exception = null)
266
 * @method static void nullOrFile(mixed $value, string $message = '', Throwable $exception = null)
267
 * @method static void allFile(mixed $value, string $message = '', Throwable $exception = null)
268
 * @method static void nullOrDirectory(mixed $value, string $message = '', Throwable $exception = null)
269
 * @method static void allDirectory(mixed $value, string $message = '', Throwable $exception = null)
270
 * @method static void nullOrReadable(string|null $value, string $message = '', Throwable $exception = null)
271
 * @method static void allReadable(iterable<string> $value, string $message = '', Throwable $exception = null)
272
 * @method static void nullOrWritable(string|null $value, string $message = '', Throwable $exception = null)
273
 * @method static void allWritable(iterable<string> $value, string $message = '', Throwable $exception = null)
274
 * @method static void nullOrClassExists(mixed $value, string $message = '', Throwable $exception = null)
275
 * @method static void allClassExists(mixed $value, string $message = '', Throwable $exception = null)
276
 * @method static void nullOrSubclassOf(mixed $value, string|object $class, string $message = '', Throwable $exception = null)
277
 * @method static void allSubclassOf(mixed $value, string|object $class, string $message = '', Throwable $exception = null)
278
 * @method static void nullOrInterfaceExists(mixed $value, string $message = '', Throwable $exception = null)
279
 * @method static void allInterfaceExists(mixed $value, string $message = '', Throwable $exception = null)
280
 * @method static void nullOrImplementsInterface(mixed $value, mixed $interface, string $message = '', Throwable $exception = null)
281
 * @method static void allImplementsInterface(mixed $value, mixed $interface, string $message = '', Throwable $exception = null)
282
 * @method static void nullOrPropertyExists(string|object|null $classOrObject, mixed $property, string $message = '', Throwable $exception = null)
283
 * @method static void allPropertyExists(iterable<string|object> $classOrObject, mixed $property, string $message = '', Throwable $exception = null)
284
 * @method static void nullOrPropertyNotExists(string|object|null $classOrObject, mixed $property, string $message = '', Throwable $exception = null)
285
 * @method static void allPropertyNotExists(iterable<string|object> $classOrObject, mixed $property, string $message = '', Throwable $exception = null)
286
 * @method static void nullOrMethodExists(string|object|null $classOrObject, mixed $method, string $message = '', Throwable $exception = null)
287
 * @method static void allMethodExists(iterable<string|object> $classOrObject, mixed $method, string $message = '', Throwable $exception = null)
288
 * @method static void nullOrMethodNotExists(string|object|null $classOrObject, mixed $method, string $message = '', Throwable $exception = null)
289
 * @method static void allMethodNotExists(iterable<string|object> $classOrObject, mixed $method, string $message = '', Throwable $exception = null)
290
 * @method static void nullOrKeyExists(array|null $array, string|int $key, string $message = '', Throwable $exception = null)
291
 * @method static void allKeyExists(iterable<array> $array, string|int $key, string $message = '', Throwable $exception = null)
292
 * @method static void nullOrKeyNotExists(array|null $array, string|int $key, string $message = '', Throwable $exception = null)
293
 * @method static void allKeyNotExists(iterable<array> $array, string|int $key, string $message = '', Throwable $exception = null)
294
 * @method static void nullOrValidArrayKey(mixed $value, string $message = '', Throwable $exception = null)
295
 * @method static void allValidArrayKey(mixed $value, string $message = '', Throwable $exception = null)
296
 * @method static void nullOrCount(Countable|array|null $array, int $number, string $message = '', Throwable $exception = null)
297
 * @method static void allCount(iterable<Countable|array> $array, int $number, string $message = '', Throwable $exception = null)
298
 * @method static void nullOrMinCount(Countable|array|null $array, int|float $min, string $message = '', Throwable $exception = null)
299
 * @method static void allMinCount(iterable<Countable|array> $array, int|float $min, string $message = '', Throwable $exception = null)
300
 * @method static void nullOrMaxCount(Countable|array|null $array, int|float $max, string $message = '', Throwable $exception = null)
301
 * @method static void allMaxCount(iterable<Countable|array> $array, int|float $max, string $message = '', Throwable $exception = null)
302
 * @method static void nullOrCountBetween(Countable|array|null $array, int|float $min, int|float $max, string $message = '', Throwable $exception = null)
303
 * @method static void allCountBetween(iterable<Countable|array> $array, int|float $min, int|float $max, string $message = '', Throwable $exception = null)
304
 * @method static void nullOrIsList(mixed $array, string $message = '', Throwable $exception = null)
305
 * @method static void allIsList(mixed $array, string $message = '', Throwable $exception = null)
306
 * @method static void nullOrIsNonEmptyList(mixed $array, string $message = '', Throwable $exception = null)
307
 * @method static void allIsNonEmptyList(mixed $array, string $message = '', Throwable $exception = null)
308
 * @method static void nullOrIsMap(mixed $array, string $message = '', Throwable $exception = null)
309
 * @method static void allIsMap(mixed $array, string $message = '', Throwable $exception = null)
310
 * @method static void nullOrIsNonEmptyMap(mixed $array, string $message = '', Throwable $exception = null)
311
 * @method static void allIsNonEmptyMap(mixed $array, string $message = '', Throwable $exception = null)
312
 * @method static void nullOrUuid(string|null $value, string $message = '', Throwable $exception = null)
313
 * @method static void allUuid(iterable<string> $value, string $message = '', Throwable $exception = null)
314
 *
315
 * @method static void nullOrThrows(Closure|null $expression, string $class, string $message = '', Throwable $exception = null)
316
 * @method static void allThrows(iterable<Closure> $expression, string $class, string $message = '', Throwable $exception = null)
317
 */
318
final class Assert
319
{
320
    private static string $base64_regex = '/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/';
321
322
323
    /**
324
     * @param string $name
325
     * @param array $arguments
326
     */
327
    public static function __callStatic($name, $arguments): void
328
    {
329
        // Handle Exception-parameter
330
        $exception = AssertionFailedException::class;
331
        $last = end($arguments);
332
        if (is_string($last) && class_exists($last) && is_subclass_of($last, Throwable::class)) {
333
            $exception = $last;
334
335
            array_pop($arguments);
336
        }
337
338
        try {
339
            if (method_exists(static::class, $name)) {
340
                call_user_func_array([static::class, $name], $arguments);
341
            } else {
342
                call_user_func_array([Webmozart::class, $name], $arguments);
343
            }
344
            return;
345
        } catch (InvalidArgumentException $e) {
346
            throw new $exception($e->getMessage());
347
        }
348
    }
349
350
351
    /***********************************************************************************
352
     *  NOTE:  Custom assertions may be added below this line.                         *
353
     *         They SHOULD be marked as `private` to ensure the call is forced         *
354
     *          through __callStatic().                                                *
355
     *         Assertions marked `public` are called directly and will                 *
356
     *          not handle any custom exception passed to it.                          *
357
     ***********************************************************************************/
358
359
360
    /**
361
     * Note: This test is not bullet-proof but prevents a string containing illegal characters
362
     * from being passed and ensures the string roughly follows the correct format for a Base64 encoded string
363
     *
364
     * @param string $value
365
     * @param string $message
366
     */
367
    private static function stringPlausibleBase64(string $value, string $message = ''): void
368
    {
369
        $result = true;
370
371
        if (filter_var($value, FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => self::$base64_regex]]) === false) {
372
            $result = false;
373
        } else {
374
            $decoded = base64_decode($value, true);
375
            if ($decoded === false) {
376
                $result = false;
377
            } elseif (base64_encode($decoded) !== $value) {
378
                $result = false;
379
            }
380
        }
381
382
        if ($result === false) {
383
            throw new InvalidArgumentException(
384
                sprintf(
385
                    $message ?: '\'%s\' is not a valid Base64 encoded string',
386
                    $value
387
                )
388
            );
389
        }
390
    }
391
392
393
    /**
394
     * @param string $value
395
     * @param string $message
396
     */
397
    private static function validDateTime(string $value, string $message = ''): void
398
    {
399
        if (DateTime::createFromFormat(DateTime::ISO8601, $value) === false) {
400
            throw new InvalidArgumentException(
401
                sprintf(
402
                    $message ?: '\'%s\' is not a valid DateTime',
403
                    $value
404
                )
405
            );
406
        }
407
    }
408
409
410
    /**
411
     * @param string $value
412
     * @param string $message
413
     */
414
    private static function validDateTimeZulu(string $value, string $message = ''): void
415
    {
416
        $dateTime = DateTime::createFromFormat(DateTime::ISO8601, $value);
417
        if ($dateTime === false) {
418
            throw new InvalidArgumentException(
419
                sprintf(
420
                    $message ?: '\'%s\' is not a valid DateTime',
421
                    $value
422
                )
423
            );
424
        } elseif ($dateTime->getTimezone()->getName() !== 'Z') {
425
            throw new InvalidArgumentException(
426
                sprintf(
427
                    $message ?: '\'%s\' is not a DateTime expressed in the UTC timezone using the \'Z\' timezone identifier.',
428
                    $value
429
                )
430
            );
431
        }
432
    }
433
434
435
    /**
436
     * @param mixed $value
437
     * @param array $values
438
     * @param string $message
439
     */
440
    private static function notInArray($value, array $values, string $message = ''): void
441
    {
442
        if (in_array($value, $values, true)) {
443
            throw new InvalidArgumentException(
444
                sprintf(
445
                    $message ?: 'Expected none of: %2$s. Got: %s',
446
                    static::valueToString($value),
447
                    implode(', ', array_map(['static', 'valueToString'], $values))
448
                )
449
            );
450
        }
451
    }
452
453
454
    /**
455
     * @param mixed $value
456
     *
457
     * @return string
458
     */
459
    protected static function valueToString($value)
460
    {
461
        if (null === $value) {
462
            return 'null';
463
        }
464
465
        if (true === $value) {
466
            return 'true';
467
        }
468
469
        if (false === $value) {
470
            return 'false';
471
        }
472
473
        if (is_array($value)) {
474
            return 'array';
475
        }
476
477
        if (is_object($value)) {
478
            if (method_exists($value, '__toString')) {
479
                return get_class($value) . ': ' . self::valueToString($value->__toString());
480
            }
481
482
            if ($value instanceof DateTime || $value instanceof DateTimeImmutable) {
483
                return get_class($value) . ': ' . self::valueToString($value->format('c'));
484
            }
485
486
            return get_class($value);
487
        }
488
489
        if (is_resource($value)) {
490
            return 'resource';
491
        }
492
493
        if (is_string($value)) {
494
            return '"' . $value . '"';
495
        }
496
497
        return (string) $value;
498
    }
499
}
500