2222 */
2323class SegmentChecker
2424{
25+ /** @var ReferenceTime */
26+ protected $ reference ;
27+
2528 /** @var Validator */
2629 protected $ validator ;
2730
@@ -30,21 +33,25 @@ public function __construct(Validator $validator = null)
3033 $ this ->validator = $ validator ?: new Validator ;
3134 }
3235
36+ public function setReference (ReferenceTime $ reference )
37+ {
38+ $ this ->reference = $ reference ;
39+ }
40+
3341 /**
3442 * Checks if a cron segment satisfies given time.
3543 *
3644 * @param string $segment
3745 * @param int $pos
38- * @param array $times
3946 *
4047 * @return bool
4148 */
42- public function checkDue (string $ segment , int $ pos, array $ times ): bool
49+ public function checkDue (string $ segment , int $ pos ): bool
4350 {
4451 $ offsets = \explode (', ' , \trim ($ segment ));
4552
4653 foreach ($ offsets as $ offset ) {
47- if ($ this ->isOffsetDue ($ offset , $ pos, $ times )) {
54+ if ($ this ->isOffsetDue ($ offset , $ pos )) {
4855 return true ;
4956 }
5057 }
@@ -57,39 +64,40 @@ public function checkDue(string $segment, int $pos, array $times): bool
5764 *
5865 * @param string $offset
5966 * @param int $pos
60- * @param array $times
6167 *
6268 * @return bool
6369 */
64- protected function isOffsetDue (string $ offset , int $ pos, array $ times ): bool
70+ protected function isOffsetDue (string $ offset , int $ pos ): bool
6571 {
6672 if (\strpos ($ offset , '/ ' ) !== false ) {
67- return $ this ->validator ->inStep ($ times [ $ pos] , $ offset );
73+ return $ this ->validator ->inStep ($ this -> reference -> get ( $ pos) , $ offset );
6874 }
6975
7076 if (\strpos ($ offset , '- ' ) !== false ) {
71- return $ this ->validator ->inRange ($ times [ $ pos] , $ offset );
77+ return $ this ->validator ->inRange ($ this -> reference -> get ( $ pos) , $ offset );
7278 }
7379
7480 if (\is_numeric ($ offset )) {
75- return $ times [ $ pos ] == $ offset ;
81+ return $ this -> reference -> isAt ( $ offset , $ pos ) ;
7682 }
7783
78- return $ this ->checkModifier ($ offset , $ pos, $ times );
84+ return $ this ->checkModifier ($ offset , $ pos );
7985 }
8086
81- protected function checkModifier (string $ offset , int $ pos, array $ times ): bool
87+ protected function checkModifier (string $ offset , int $ pos ): bool
8288 {
8389 $ isModifier = \strpbrk ($ offset , 'LCW# ' );
8490
85- if ($ pos === 2 && $ isModifier ) {
86- return $ this ->validator ->isValidMonthDay ($ offset , $ times );
91+ if ($ pos === ReferenceTime:: MONTHDAY && $ isModifier ) {
92+ return $ this ->validator ->isValidMonthDay ($ offset , $ this -> reference );
8793 }
8894
89- if ($ pos === 4 && $ isModifier ) {
90- return $ this ->validator ->isValidWeekDay ($ offset , $ times );
95+ if ($ pos === ReferenceTime:: WEEKDAY && $ isModifier ) {
96+ return $ this ->validator ->isValidWeekDay ($ offset , $ this -> reference );
9197 }
9298
9399 $ this ->validator ->unexpectedValue ($ pos , $ offset );
100+ // @codeCoverageIgnoreStart
94101 }
102+ // @codeCoverageIgnoreEnd
95103}
0 commit comments