1 | <?php |
||
20 | class WeekInterval implements ComparableIntervalInterface |
||
21 | { |
||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | const REGEXP = '/^ |
||
26 | (?:\(|\[) # start type char |
||
27 | \s* |
||
28 | (?<start>\d{4}-\d{2}-\d{2}) # start point |
||
29 | \s*,\s* # separator |
||
30 | (?<end>\d{4}-\d{2}-\d{2}) # 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 WeekIntervalPoint |
||
47 | */ |
||
48 | private $start; |
||
49 | |||
50 | /** |
||
51 | * @var WeekIntervalPoint |
||
52 | */ |
||
53 | private $end; |
||
54 | |||
55 | /** |
||
56 | * @param WeekIntervalPoint $start |
||
57 | * @param WeekIntervalPoint $end |
||
58 | * @param IntervalType $type |
||
59 | */ |
||
60 | 2 | private function __construct(WeekIntervalPoint $start, WeekIntervalPoint $end, IntervalType $type) |
|
71 | |||
72 | /** |
||
73 | * @param \DateTime $start |
||
74 | * @param \DateTime $end |
||
75 | * @param IntervalType $type |
||
76 | * |
||
77 | * @return self |
||
78 | */ |
||
79 | 2 | 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-12-09, 2016-12-21] |
||
133 | * (2015-03-07, 2015-10-19] |
||
134 | * [2014-09-11, 2015-02-08) |
||
135 | * (2013-10-02, 2013-10-30) |
||
136 | * |
||
137 | * Spaces are ignored in format. |
||
138 | * |
||
139 | * @param string $string |
||
140 | * |
||
141 | * @return self |
||
142 | */ |
||
143 | 2 | public static function fromString($string) |
|
155 | |||
156 | /** |
||
157 | * @param WeekInterval $interval |
||
158 | * |
||
159 | * @return bool |
||
160 | */ |
||
161 | public function equal(WeekInterval $interval) |
||
165 | |||
166 | /** |
||
167 | * @param \DateTime $point |
||
168 | * |
||
169 | * @return bool |
||
170 | */ |
||
171 | public function contains(\DateTime $point) |
||
175 | |||
176 | /** |
||
177 | * @param WeekInterval $interval |
||
178 | * |
||
179 | * @return bool |
||
180 | */ |
||
181 | public function intersects(WeekInterval $interval) |
||
185 | |||
186 | /** |
||
187 | * @param WeekInterval $interval |
||
188 | * |
||
189 | * @return WeekInterval|null |
||
190 | */ |
||
191 | public function intersection(WeekInterval $interval) |
||
195 | |||
196 | /** |
||
197 | * The point is before the interval. |
||
198 | * |
||
199 | * @param \DateTime $point |
||
200 | * |
||
201 | * @return bool |
||
202 | */ |
||
203 | public function before(\DateTime $point) |
||
207 | |||
208 | /** |
||
209 | * The point is after the interval. |
||
210 | * |
||
211 | * @param \DateTime $point |
||
212 | * |
||
213 | * @return bool |
||
214 | */ |
||
215 | public function after(\DateTime $point) |
||
219 | |||
220 | /** |
||
221 | * @return IntervalType |
||
222 | */ |
||
223 | public function type() |
||
227 | |||
228 | /** |
||
229 | * @return \DateTime |
||
230 | */ |
||
231 | public function start() |
||
235 | |||
236 | /** |
||
237 | * @return \DateTime |
||
238 | */ |
||
239 | public function end() |
||
243 | |||
244 | /** |
||
245 | * @return WeekIntervalPoint |
||
246 | */ |
||
247 | 1 | public function startPoint() |
|
251 | |||
252 | /** |
||
253 | * @return WeekIntervalPoint |
||
254 | */ |
||
255 | 1 | public function endPoint() |
|
259 | |||
260 | /** |
||
261 | * Returns a copy of this Interval with the start point altered. |
||
262 | * |
||
263 | * @param IntervalPointInterface|WeekIntervalPoint $start |
||
264 | * |
||
265 | * @return self |
||
266 | */ |
||
267 | public function withStart(IntervalPointInterface $start) |
||
271 | |||
272 | /** |
||
273 | * Returns a copy of this Interval with the end point altered. |
||
274 | * |
||
275 | * @param IntervalPointInterface|WeekIntervalPoint $end |
||
276 | * |
||
277 | * @return self |
||
278 | */ |
||
279 | public function withEnd(IntervalPointInterface $end) |
||
283 | |||
284 | /** |
||
285 | * Returns a copy of this Interval with the interval type altered. |
||
286 | * |
||
287 | * @param IntervalType $type |
||
288 | * |
||
289 | * @return self |
||
290 | */ |
||
291 | public function withType(IntervalType $type) |
||
295 | |||
296 | /** |
||
297 | * @return string |
||
298 | */ |
||
299 | 1 | public function __toString() |
|
303 | } |
||
304 |
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.