1 | <?php |
||
10 | trait GuardTrait |
||
11 | { |
||
12 | abstract function isEmpty(); |
||
13 | |||
14 | abstract function count(); |
||
15 | |||
16 | /** |
||
17 | * Ensures that we throw the correct exception when an empty collection is found |
||
18 | * @param $method |
||
19 | * @throws EmptyException |
||
20 | */ |
||
21 | protected function emptyGuard($method) |
||
27 | |||
28 | /** |
||
29 | * Validates if a key is withing bounds (usually only useful with vectors) |
||
30 | * @param $key |
||
31 | */ |
||
32 | 5 | protected function validateKeyBounds($key) |
|
38 | |||
39 | /** |
||
40 | * @param $key |
||
41 | */ |
||
42 | protected function validateKeyDoesNotExists($key) |
||
48 | |||
49 | /** |
||
50 | * @param $key |
||
51 | */ |
||
52 | protected function validateKeyExists($key) |
||
58 | 19 | ||
59 | /** |
||
60 | * @param int $element |
||
61 | * @return bool |
||
62 | */ |
||
63 | protected function isBoundedKey($element) |
||
67 | |||
68 | /** |
||
69 | * Validate if an element respects the correct type (usually only useful with vectors) |
||
70 | * @param $element |
||
71 | * @throws TypeException |
||
72 | */ |
||
73 | protected function validateKeyType($element) |
||
79 | |||
80 | protected function validateTraversable($traversable) |
||
86 | } |
||
87 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.