1 | <?php |
||
12 | final class ArrayEnsurance implements EnsuranceInterface |
||
13 | { |
||
14 | use EnsuranceTrait; |
||
15 | |||
16 | /** |
||
17 | * ArrayEnsurance constructor. |
||
18 | * |
||
19 | * @param EnsuranceInterface $ensurance |
||
20 | */ |
||
21 | public function __construct(EnsuranceInterface $ensurance) |
||
26 | 9 | ||
27 | /** |
||
28 | * @param callable $callback |
||
29 | * |
||
30 | * @return array |
||
31 | */ |
||
32 | private function filterBy(callable $callback): array |
||
36 | |||
37 | 1 | /** |
|
38 | * @param callable $callback |
||
39 | * |
||
40 | * @return ArrayEnsurance |
||
41 | */ |
||
42 | public function all(callable $callback): self |
||
48 | |||
49 | 1 | /** |
|
50 | * @param callable $callback |
||
51 | * |
||
52 | * @return ArrayEnsurance |
||
53 | */ |
||
54 | public function any(callable $callback): self |
||
60 | 1 | ||
61 | /** |
||
62 | 1 | * @param string $type |
|
63 | * |
||
64 | * @return ArrayEnsurance |
||
|
|||
65 | * @throws \Exception |
||
66 | */ |
||
67 | public function allTypeOf(string $type): self |
||
75 | 1 | ||
76 | /** |
||
77 | * @param string $type |
||
78 | * |
||
79 | * @return ArrayEnsurance |
||
80 | * @throws \Exception |
||
81 | */ |
||
82 | public function anyTypeOf(string $type): self |
||
90 | |||
91 | /** |
||
92 | * @param mixed $key |
||
93 | * |
||
94 | * @return ArrayEnsurance |
||
95 | */ |
||
96 | 1 | public function hasKey($key): self |
|
103 | |||
104 | /** |
||
105 | * @param mixed $value |
||
106 | * |
||
107 | * @return ArrayEnsurance |
||
108 | */ |
||
109 | 1 | public function hasValue($value): self |
|
116 | |||
117 | /** |
||
118 | * @param int $length |
||
119 | * |
||
120 | 1 | * @return ArrayEnsurance |
|
121 | */ |
||
122 | 1 | public function hasLengthOf(int $length): self |
|
129 | |||
130 | /** |
||
131 | 1 | * @param int $length |
|
132 | * |
||
133 | 1 | * @return ArrayEnsurance |
|
134 | 1 | */ |
|
135 | public function isShorterThan(int $length): self |
||
142 | |||
143 | /** |
||
144 | * @param int $length |
||
145 | * |
||
146 | * @return ArrayEnsurance |
||
147 | */ |
||
148 | public function isShorterOrEqualsTo(int $length): self |
||
155 | |||
156 | /** |
||
157 | * @param int $length |
||
158 | * |
||
159 | * @return ArrayEnsurance |
||
160 | */ |
||
161 | public function isLongerThan(int $length): self |
||
168 | |||
169 | /** |
||
170 | * @param int $length |
||
171 | * |
||
172 | * @return ArrayEnsurance |
||
173 | */ |
||
174 | public function isLongerOrEqualTo(int $length): self |
||
181 | |||
182 | /** |
||
183 | * @return ArrayEnsurance |
||
184 | */ |
||
185 | public function isAssociative(): self |
||
193 | |||
194 | /** |
||
195 | * @return ArrayEnsurance |
||
196 | */ |
||
197 | public function isNotAssociative(): self |
||
205 | |||
206 | /** |
||
207 | * @return ArrayEnsurance |
||
208 | */ |
||
209 | public function isCallable(): self |
||
215 | } |
||
216 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.