1 | <?php |
||
20 | class YearInterval implements ComparableIntervalInterface |
||
21 | { |
||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | const REGEXP = '/^ |
||
26 | (?:\(|\[) # start type char |
||
27 | \s* |
||
28 | (?<start>\d{4}) # start point |
||
29 | \s*,\s* # separator |
||
30 | (?<end>\d{4}) # 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 YearIntervalPoint |
||
47 | */ |
||
48 | private $start; |
||
49 | |||
50 | /** |
||
51 | * @var YearIntervalPoint |
||
52 | */ |
||
53 | private $end; |
||
54 | |||
55 | /** |
||
56 | * @param YearIntervalPoint $start |
||
57 | * @param YearIntervalPoint $end |
||
58 | * @param IntervalType $type |
||
59 | */ |
||
60 | private function __construct(YearIntervalPoint $start, YearIntervalPoint $end, IntervalType $type) |
||
71 | |||
72 | /** |
||
73 | * @param \DateTime $start |
||
74 | * @param \DateTime $end |
||
75 | * @param IntervalType $type |
||
76 | * |
||
77 | * @return self |
||
78 | */ |
||
79 | public static function create(\DateTime $start, \DateTime $end, IntervalType $type) |
||
83 | |||
84 | /** |
||
85 | * @param \DateTime $start |
||
86 | * @param \DateTime $end |
||
87 | * |
||
88 | * @return self |
||
89 | */ |
||
90 | public static function closed(\DateTime $start, \DateTime $end) |
||
94 | |||
95 | /** |
||
96 | * @param \DateTime $start |
||
97 | * @param \DateTime $end |
||
98 | * |
||
99 | * @return self |
||
100 | */ |
||
101 | public static function halfClosed(\DateTime $start, \DateTime $end) |
||
105 | |||
106 | /** |
||
107 | * @param \DateTime $start |
||
108 | * @param \DateTime $end |
||
109 | * |
||
110 | * @return self |
||
111 | */ |
||
112 | public static function halfOpen(\DateTime $start, \DateTime $end) |
||
116 | |||
117 | /** |
||
118 | * @param \DateTime $start |
||
119 | * @param \DateTime $end |
||
120 | * |
||
121 | * @return self |
||
122 | */ |
||
123 | public static function open(\DateTime $start, \DateTime $end) |
||
127 | |||
128 | /** |
||
129 | * Create interval from string. |
||
130 | * |
||
131 | * Example formats for all interval types: |
||
132 | * [2016, 2017] |
||
133 | * (2015, 2016] |
||
134 | * [2014, 2015) |
||
135 | * (2013, 2014) |
||
136 | * |
||
137 | * Spaces are ignored in format. |
||
138 | * |
||
139 | * @param string $string |
||
140 | * |
||
141 | * @return self |
||
142 | */ |
||
143 | public static function fromString($string) |
||
155 | |||
156 | /** |
||
157 | * @param YearInterval $interval |
||
158 | * |
||
159 | * @return bool |
||
160 | */ |
||
161 | public function equal(YearInterval $interval) |
||
165 | |||
166 | /** |
||
167 | * @param \DateTime $point |
||
168 | * |
||
169 | * @return bool |
||
170 | */ |
||
171 | public function contains(\DateTime $point) |
||
175 | |||
176 | /** |
||
177 | * @param YearInterval $interval |
||
178 | * @param bool $check_interval_type |
||
179 | * |
||
180 | * @return bool |
||
181 | */ |
||
182 | public function intersects(YearInterval $interval, $check_interval_type = true) |
||
186 | |||
187 | /** |
||
188 | * @param YearInterval $interval |
||
189 | * |
||
190 | * @return YearInterval|null |
||
191 | */ |
||
192 | public function intersection(YearInterval $interval) |
||
196 | |||
197 | /** |
||
198 | * The point is before the interval. |
||
199 | * |
||
200 | * @param \DateTime $point |
||
201 | * |
||
202 | * @return bool |
||
203 | */ |
||
204 | public function before(\DateTime $point) |
||
208 | |||
209 | /** |
||
210 | * The point is after the interval. |
||
211 | * |
||
212 | * @param \DateTime $point |
||
213 | * |
||
214 | * @return bool |
||
215 | */ |
||
216 | public function after(\DateTime $point) |
||
220 | |||
221 | /** |
||
222 | * @return IntervalType |
||
223 | */ |
||
224 | public function type() |
||
228 | |||
229 | /** |
||
230 | * @return \DateTime |
||
231 | */ |
||
232 | public function start() |
||
236 | |||
237 | /** |
||
238 | * @return \DateTime |
||
239 | */ |
||
240 | public function end() |
||
244 | |||
245 | /** |
||
246 | * @return YearIntervalPoint |
||
247 | */ |
||
248 | public function startPoint() |
||
252 | |||
253 | /** |
||
254 | * @return YearIntervalPoint |
||
255 | */ |
||
256 | public function endPoint() |
||
260 | |||
261 | /** |
||
262 | * Returns a copy of this Interval with the start point altered. |
||
263 | * |
||
264 | * @param IntervalPointInterface|YearIntervalPoint $start |
||
265 | * |
||
266 | * @return self |
||
267 | */ |
||
268 | public function withStart(IntervalPointInterface $start) |
||
272 | |||
273 | /** |
||
274 | * Returns a copy of this Interval with the end point altered. |
||
275 | * |
||
276 | * @param IntervalPointInterface|YearIntervalPoint $end |
||
277 | * |
||
278 | * @return self |
||
279 | */ |
||
280 | public function withEnd(IntervalPointInterface $end) |
||
284 | |||
285 | /** |
||
286 | * Returns a copy of this Interval with the interval type altered. |
||
287 | * |
||
288 | * @param IntervalType $type |
||
289 | * |
||
290 | * @return self |
||
291 | */ |
||
292 | public function withType(IntervalType $type) |
||
296 | |||
297 | /** |
||
298 | * @return string |
||
299 | */ |
||
300 | public function __toString() |
||
304 | } |
||
305 |
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.