| Conditions | 8 |
| Paths | 5 |
| Total Lines | 20 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 9 |
| CRAP Score | 8 |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 21 | public static function validate(Recurrence $recurrence) |
||
| 22 | { |
||
| 23 | 1 | if (!$recurrence->getFrequency()) { |
|
| 24 | 1 | throw new InvalidRecurrenceException('Frequency is required'); |
|
| 25 | } |
||
| 26 | |||
| 27 | 1 | if ($recurrence->hasCount() && $recurrence->getPeriodEndAt()) { |
|
| 28 | 1 | throw new InvalidRecurrenceException('Recurrence cannot have [COUNT] and [UNTIL] option at the same time'); |
|
| 29 | } |
||
| 30 | |||
| 31 | 1 | if (!$recurrence->hasCount() && !$recurrence->getPeriodEndAt()) { |
|
| 32 | 1 | throw new InvalidRecurrenceException('Recurrence required [COUNT] or [UNTIL] option'); |
|
| 33 | } |
||
| 34 | |||
| 35 | 1 | if ($recurrence->hasConstraint(EndOfMonthConstraint::class) && (string) $recurrence->getFrequency() != Frequency::FREQUENCY_MONTHLY) { |
|
| 36 | 1 | throw new InvalidRecurrenceException('End of month constraint can be applied only with monthly frequency'); |
|
| 37 | } |
||
| 38 | |||
| 39 | 1 | return true; |
|
| 40 | } |
||
| 41 | } |
||
| 42 |