1 | <?php |
||
19 | class YearInterval implements ComparableIntervalInterface |
||
20 | { |
||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | const REGEXP = '/^ |
||
25 | (?:\(|\[) # start type char |
||
26 | \s* |
||
27 | (?<start>\d{4}) # start point |
||
28 | \s*,\s* # separator |
||
29 | (?<end>\d{4}) # end point |
||
30 | \s* |
||
31 | (?:\)|\]) # end type char |
||
32 | $/x'; |
||
33 | |||
34 | /** |
||
35 | * @var IntervalType |
||
36 | */ |
||
37 | private $type; |
||
38 | |||
39 | /** |
||
40 | * @var IntervalComparator |
||
41 | */ |
||
42 | private $comparator; |
||
43 | |||
44 | /** |
||
45 | * @var YearIntervalPoint |
||
46 | */ |
||
47 | private $start; |
||
48 | |||
49 | /** |
||
50 | * @var YearIntervalPoint |
||
51 | */ |
||
52 | private $end; |
||
53 | |||
54 | /** |
||
55 | * @param YearIntervalPoint $start |
||
56 | * @param YearIntervalPoint $end |
||
57 | * @param IntervalType $type |
||
58 | */ |
||
59 | private function __construct(YearIntervalPoint $start, YearIntervalPoint $end, IntervalType $type) |
||
70 | |||
71 | /** |
||
72 | * @param \DateTime $start |
||
73 | * @param \DateTime $end |
||
74 | * @param IntervalType $type |
||
75 | * |
||
76 | * @return self |
||
77 | */ |
||
78 | public static function create(\DateTime $start, \DateTime $end, IntervalType $type) |
||
82 | |||
83 | /** |
||
84 | * @param \DateTime $start |
||
85 | * @param \DateTime $end |
||
86 | * |
||
87 | * @return self |
||
88 | */ |
||
89 | public static function closed(\DateTime $start, \DateTime $end) |
||
93 | |||
94 | /** |
||
95 | * @param \DateTime $start |
||
96 | * @param \DateTime $end |
||
97 | * |
||
98 | * @return self |
||
99 | */ |
||
100 | public static function halfClosed(\DateTime $start, \DateTime $end) |
||
104 | |||
105 | /** |
||
106 | * @param \DateTime $start |
||
107 | * @param \DateTime $end |
||
108 | * |
||
109 | * @return self |
||
110 | */ |
||
111 | public static function halfOpen(\DateTime $start, \DateTime $end) |
||
115 | |||
116 | /** |
||
117 | * @param \DateTime $start |
||
118 | * @param \DateTime $end |
||
119 | * |
||
120 | * @return self |
||
121 | */ |
||
122 | public static function open(\DateTime $start, \DateTime $end) |
||
126 | |||
127 | /** |
||
128 | * Create interval from string. |
||
129 | * |
||
130 | * Example formats for all interval types: |
||
131 | * [2016, 2017] |
||
132 | * (2015, 2016] |
||
133 | * [2014, 2015) |
||
134 | * (2013, 2014) |
||
135 | * |
||
136 | * Spaces are ignored in format. |
||
137 | * |
||
138 | * @param string $string |
||
139 | * |
||
140 | * @return self |
||
141 | */ |
||
142 | public static function fromString($string) |
||
154 | |||
155 | /** |
||
156 | * @param \DateTime $point |
||
157 | * |
||
158 | * @return bool |
||
159 | */ |
||
160 | public function contains(\DateTime $point) |
||
164 | |||
165 | /** |
||
166 | * @param YearInterval $interval |
||
167 | * @param bool $check_interval_type |
||
168 | * |
||
169 | * @return bool |
||
170 | */ |
||
171 | public function intersects(YearInterval $interval, $check_interval_type = true) |
||
175 | |||
176 | /** |
||
177 | * @param YearInterval $interval |
||
178 | * |
||
179 | * @return YearInterval|null |
||
180 | */ |
||
181 | public function intersection(YearInterval $interval) |
||
185 | |||
186 | /** |
||
187 | * The point is before the interval |
||
188 | * |
||
189 | * @param \DateTime $point |
||
190 | * |
||
191 | * @return bool |
||
192 | */ |
||
193 | public function before(\DateTime $point) |
||
197 | |||
198 | /** |
||
199 | * The point is after the interval |
||
200 | * |
||
201 | * @param \DateTime $point |
||
202 | * |
||
203 | * @return bool |
||
204 | */ |
||
205 | public function after(\DateTime $point) |
||
209 | |||
210 | /** |
||
211 | * @return IntervalType |
||
212 | */ |
||
213 | public function type() |
||
217 | |||
218 | /** |
||
219 | * @return \DateTime |
||
220 | */ |
||
221 | public function start() |
||
225 | |||
226 | /** |
||
227 | * @return \DateTime |
||
228 | */ |
||
229 | public function end() |
||
233 | |||
234 | /** |
||
235 | * @return YearIntervalPoint |
||
236 | */ |
||
237 | public function startPoint() |
||
241 | |||
242 | /** |
||
243 | * @return YearIntervalPoint |
||
244 | */ |
||
245 | public function endPoint() |
||
249 | |||
250 | /** |
||
251 | * Returns a copy of this Interval with the start point altered. |
||
252 | * |
||
253 | * @param IntervalPointInterface|YearIntervalPoint $start |
||
254 | * |
||
255 | * @return self |
||
256 | */ |
||
257 | public function withStart(IntervalPointInterface $start) |
||
261 | |||
262 | /** |
||
263 | * Returns a copy of this Interval with the end point altered. |
||
264 | * |
||
265 | * @param IntervalPointInterface|YearIntervalPoint $end |
||
266 | * |
||
267 | * @return self |
||
268 | */ |
||
269 | public function withEnd(IntervalPointInterface $end) |
||
273 | |||
274 | /** |
||
275 | * Returns a copy of this Interval with the interval type altered. |
||
276 | * |
||
277 | * @param IntervalType $type |
||
278 | * |
||
279 | * @return self |
||
280 | */ |
||
281 | public function withType(IntervalType $type) |
||
285 | |||
286 | /** |
||
287 | * @return string |
||
288 | */ |
||
289 | public function __toString() |
||
293 | } |
||
294 |
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.