| Conditions | 4 |
| Paths | 8 |
| Total Lines | 28 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 20 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php declare(strict_types=1); |
||
| 17 | protected function validate($input): Timestamp |
||
| 18 | { |
||
| 19 | $settings = $this->getSettings(); |
||
| 20 | $before = $settings['before'] ?? false; |
||
| 21 | $after = $settings['after'] ?? false; |
||
| 22 | |||
| 23 | if (!$input instanceof Timestamp) { |
||
| 24 | Assertion::notEmpty($input, 'Must not be empty.'); |
||
| 25 | $timestamp = Timestamp::fromNative($input); |
||
| 26 | } else { |
||
| 27 | $timestamp = $input; |
||
| 28 | } |
||
| 29 | |||
| 30 | if ($before !== false) { |
||
| 31 | Assertion::true( |
||
| 32 | $timestamp->isBefore(Timestamp::fromNative($before)), |
||
| 33 | 'Timestamp must be before given time.' |
||
| 34 | ); |
||
| 35 | } |
||
| 36 | |||
| 37 | if ($after !== false) { |
||
| 38 | Assertion::true( |
||
| 39 | $timestamp->isAfter(Timestamp::fromNative($after)), |
||
| 40 | 'Timestamp must be after given time.' |
||
| 41 | ); |
||
| 42 | } |
||
| 43 | |||
| 44 | return $timestamp; |
||
| 45 | } |
||
| 47 |