1 | <?php |
||
20 | class IPv6Interval implements ComparableIntervalInterface |
||
21 | { |
||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | const REGEXP = '/^ |
||
26 | (?:\(|\[) # start type char |
||
27 | \s* |
||
28 | (?<start>'.IPv6IntervalPoint::IPV6_ADDR.') # start point |
||
29 | \s*,\s* # separator |
||
30 | (?<end>'.IPv6IntervalPoint::IPV6_ADDR.') # end point |
||
31 | \s* |
||
32 | (?:\)|\]) # end type char |
||
33 | $/x'; |
||
34 | |||
35 | /** |
||
36 | * @var IntervalType |
||
37 | */ |
||
38 | private $type; |
||
39 | |||
40 | /** |
||
41 | * @var IntervalComparator |
||
42 | */ |
||
43 | private $comparator; |
||
44 | |||
45 | /** |
||
46 | * @var IPv6IntervalPoint |
||
47 | */ |
||
48 | private $start; |
||
49 | |||
50 | /** |
||
51 | * @var IPv6IntervalPoint |
||
52 | */ |
||
53 | private $end; |
||
54 | |||
55 | /** |
||
56 | * @param IPv6IntervalPoint $start |
||
57 | * @param IPv6IntervalPoint $end |
||
58 | * @param IntervalType $type |
||
59 | */ |
||
60 | 4 | private function __construct(IPv6IntervalPoint $start, IPv6IntervalPoint $end, IntervalType $type) |
|
71 | |||
72 | /** |
||
73 | * @param string $start |
||
74 | * @param string $end |
||
75 | * @param IntervalType $type |
||
76 | * |
||
77 | * @return self |
||
78 | */ |
||
79 | 4 | public static function create($start, $end, IntervalType $type) |
|
83 | |||
84 | /** |
||
85 | * @param string $start |
||
86 | * @param string $end |
||
87 | * |
||
88 | * @return self |
||
89 | */ |
||
90 | 1 | public static function closed($start, $end) |
|
94 | |||
95 | /** |
||
96 | * @param string $start |
||
97 | * @param string $end |
||
98 | * |
||
99 | * @return self |
||
100 | */ |
||
101 | 1 | public static function halfClosed($start, $end) |
|
105 | |||
106 | /** |
||
107 | * @param string $start |
||
108 | * @param string $end |
||
109 | * |
||
110 | * @return self |
||
111 | */ |
||
112 | 1 | public static function halfOpen($start, $end) |
|
116 | |||
117 | /** |
||
118 | * @param string $start |
||
119 | * @param string $end |
||
120 | * |
||
121 | * @return self |
||
122 | */ |
||
123 | 1 | public static function open($start, $end) |
|
127 | |||
128 | /** |
||
129 | * Create interval from string. |
||
130 | * |
||
131 | * Example formats for all interval types: |
||
132 | * [fe80::, febf::] |
||
133 | * (fe80::, febf::] |
||
134 | * [fec0::, feff::) |
||
135 | * (fec0::, feff::) |
||
136 | * |
||
137 | * Spaces are ignored in format. |
||
138 | * |
||
139 | * @param string $string |
||
140 | * |
||
141 | * @return self |
||
142 | */ |
||
143 | 4 | public static function fromString($string) |
|
153 | |||
154 | /** |
||
155 | * Checks if this interval is equal to the specified interval. |
||
156 | * |
||
157 | * @param IPv6Interval $interval |
||
158 | * |
||
159 | * @return bool |
||
160 | */ |
||
161 | public function equal(self $interval) |
||
165 | |||
166 | /** |
||
167 | * Does this interval contain the specified point. |
||
168 | * |
||
169 | * @param string $point |
||
170 | * |
||
171 | * @return bool |
||
172 | */ |
||
173 | public function contains($point) |
||
177 | |||
178 | /** |
||
179 | * Does this interval intersect the specified interval. |
||
180 | * |
||
181 | * @param IPv6Interval $interval |
||
182 | * |
||
183 | * @return bool |
||
184 | */ |
||
185 | public function intersects(self $interval) |
||
189 | |||
190 | /** |
||
191 | * Gets the intersection between this interval and another interval. |
||
192 | * |
||
193 | * @param IPv6Interval $interval |
||
194 | * |
||
195 | * @return self|null |
||
196 | */ |
||
197 | public function intersection(self $interval) |
||
201 | |||
202 | /** |
||
203 | * Gets the covered interval between this Interval and another interval. |
||
204 | * |
||
205 | * @param IPv6Interval $interval |
||
206 | * |
||
207 | * @return self |
||
208 | */ |
||
209 | public function cover(self $interval) |
||
213 | |||
214 | /** |
||
215 | * Gets the gap between this interval and another interval. |
||
216 | * |
||
217 | * @param IPv6Interval $interval |
||
218 | * |
||
219 | * @return self|null |
||
220 | */ |
||
221 | public function gap(self $interval) |
||
225 | |||
226 | /** |
||
227 | * Does this interval abuts with the interval specified. |
||
228 | * |
||
229 | * @param IPv6Interval $interval |
||
230 | * |
||
231 | * @return bool |
||
232 | */ |
||
233 | public function abuts(self $interval) |
||
237 | |||
238 | /** |
||
239 | * Joins the interval between the adjacent. |
||
240 | * |
||
241 | * @param IPv6Interval $interval |
||
242 | * |
||
243 | * @return self|null |
||
244 | */ |
||
245 | public function join(self $interval) |
||
249 | |||
250 | /** |
||
251 | * Gets the union between this interval and another interval. |
||
252 | * |
||
253 | * @param IPv6Interval $interval |
||
254 | * |
||
255 | * @return self|null |
||
256 | */ |
||
257 | public function union(self $interval) |
||
261 | |||
262 | /** |
||
263 | * The point is before the interval. |
||
264 | * |
||
265 | * @param string $point |
||
266 | * |
||
267 | * @return bool |
||
268 | */ |
||
269 | 4 | public function before($point) |
|
273 | |||
274 | /** |
||
275 | * The point is after the interval. |
||
276 | * |
||
277 | * @param string $point |
||
278 | * |
||
279 | * @return bool |
||
280 | */ |
||
281 | public function after($point) |
||
285 | |||
286 | /** |
||
287 | * @return IntervalType |
||
288 | */ |
||
289 | 4 | public function type() |
|
293 | |||
294 | /** |
||
295 | * @return string |
||
296 | */ |
||
297 | 4 | public function start() |
|
301 | |||
302 | /** |
||
303 | * @return string |
||
304 | */ |
||
305 | 4 | public function end() |
|
309 | |||
310 | /** |
||
311 | * @return IPv6IntervalPoint |
||
312 | */ |
||
313 | 4 | public function startPoint() |
|
317 | |||
318 | /** |
||
319 | * @return IPv6IntervalPoint |
||
320 | */ |
||
321 | 4 | public function endPoint() |
|
325 | |||
326 | /** |
||
327 | * Returns a copy of this Interval with the start point altered. |
||
328 | * |
||
329 | * @param IntervalPointInterface|IPv6IntervalPoint $start |
||
330 | * |
||
331 | * @return self |
||
332 | */ |
||
333 | public function withStart(IntervalPointInterface $start) |
||
337 | |||
338 | /** |
||
339 | * Returns a copy of this Interval with the end point altered. |
||
340 | * |
||
341 | * @param IntervalPointInterface|IPv6IntervalPoint $end |
||
342 | * |
||
343 | * @return self |
||
344 | */ |
||
345 | public function withEnd(IntervalPointInterface $end) |
||
349 | |||
350 | /** |
||
351 | * Returns a copy of this Interval with the interval type altered. |
||
352 | * |
||
353 | * @param IntervalType $type |
||
354 | * |
||
355 | * @return self |
||
356 | */ |
||
357 | public function withType(IntervalType $type) |
||
361 | |||
362 | /** |
||
363 | * @return string |
||
364 | */ |
||
365 | 4 | public function __toString() |
|
369 | } |
||
370 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.