Total Complexity | 14 |
Total Lines | 61 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | final class Assertions |
||
10 | { |
||
11 | /** |
||
12 | * @param mixed $ttl |
||
13 | * |
||
14 | * @throws \RemotelyLiving\PHPCacheAdapter\Exceptions\InvalidArgument |
||
15 | */ |
||
16 | public static function assertValidTTL($ttl): void |
||
17 | { |
||
18 | if (is_null($ttl) || is_int($ttl) || (is_object($ttl) && $ttl instanceof \DateTime)) { |
||
19 | return; |
||
20 | } |
||
21 | |||
22 | throw Exceptions\InvalidArgument::invalidTTL(); |
||
23 | } |
||
24 | |||
25 | /** |
||
26 | * @param mixed $key |
||
27 | * |
||
28 | * @throws \RemotelyLiving\PHPCacheAdapter\Exceptions\InvalidArgument |
||
29 | */ |
||
30 | public static function assertValidKey($key): void |
||
31 | { |
||
32 | if (!is_string($key) || preg_match('/\s/im', $key)) { |
||
33 | throw Exceptions\InvalidArgument::invalidKey($key); |
||
34 | } |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * @param mixed $keys |
||
39 | * |
||
40 | * @throws \RemotelyLiving\PHPCacheAdapter\Exceptions\InvalidArgument |
||
41 | */ |
||
42 | public static function assertValidKeys($keys): void |
||
43 | { |
||
44 | self::assertIterable($keys); |
||
45 | |||
46 | foreach ($keys as $key) { |
||
47 | self::assertValidKey($key); |
||
48 | } |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * @param mixed $iterable |
||
53 | * |
||
54 | * @throws \RemotelyLiving\PHPCacheAdapter\Exceptions\InvalidArgument |
||
55 | */ |
||
56 | public static function assertIterable($iterable): void |
||
60 | } |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * @throws \RemotelyLiving\PHPCacheAdapter\Exceptions\RuntimeError |
||
65 | */ |
||
66 | public static function assertExtensionLoaded(string $extension): void |
||
70 | } |
||
71 | } |
||
72 | } |
||
73 |