1 | <?php |
||
9 | trait GuardTrait |
||
10 | { |
||
11 | abstract function isEmpty(); |
||
12 | |||
13 | abstract function count(); |
||
14 | |||
15 | /** |
||
16 | * Ensures that we throw the correct exception when an empty collection is found |
||
17 | * @param $method |
||
18 | * @throws EmptyException |
||
19 | */ |
||
20 | protected function emptyGuard($method) |
||
28 | |||
29 | /** |
||
30 | * Validates if a key is withing bounds (usually only useful with vectors) |
||
31 | * @param $key |
||
32 | 5 | */ |
|
33 | protected function validateKeyBounds($key) |
||
39 | |||
40 | /** |
||
41 | * @param int $element |
||
42 | * @return bool |
||
43 | 5 | */ |
|
44 | protected function isBoundedKey($element) |
||
48 | |||
49 | /** |
||
50 | * Validate if an element respects the correct type (usually only useful with vectors) |
||
51 | * @param $element |
||
52 | * @throws TypeException |
||
53 | 22 | */ |
|
54 | protected function validateKeyType($element) |
||
60 | |||
61 | protected function validateTraversable($traversable) |
||
67 | } |
||
68 |
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.