Passed
Branch factorize (4cfa74)
by Samuel
01:51
created

RecurrenceValidator::validate()   B

Complexity

Conditions 6
Paths 4

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
ccs 7
cts 7
cp 1
rs 8.8571
cc 6
eloc 8
nc 4
nop 1
crap 6
1
<?php
2
3
namespace Recurrence\Validator;
4
5
use Recurrence\Model\Recurrence;
6
use Recurrence\Model\Exception\InvalidRecurrenceException;
7
8
/**
9
 * Class RecurrenceValidator
10
 * @package Recurrence\Validator
11
 */
12
class RecurrenceValidator
13
{
14
    /**
15
     * @param Recurrence $recurrence
16
     * @throws InvalidRecurrenceException
17
     * @return bool
18
     */
19
    public static function validate(Recurrence $recurrence)
20
    {
21 1
        if (!$recurrence->getFrequency()) {
22 1
            throw new InvalidRecurrenceException('Frequency is required');
23
        }
24
25 1
        if ($recurrence->hasCount() && $recurrence->getPeriodEndAt()) {
26 1
            throw new InvalidRecurrenceException('Recurrence cannot have [COUNT] and [UNTIL] option at the same time');
27
        }
28
29 1
        if (!$recurrence->hasCount() && !$recurrence->getPeriodEndAt()) {
30 1
            throw new InvalidRecurrenceException('Recurrence required [COUNT] or [UNTIL] option');
31
        }
32
33 1
        return true;
34
    }
35
}
36