Passed
Push — master ( ed2711...5bfb66 )
by Samuel
02:22
created

UntilTimezonedTransformer::validate()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 10
cc 4
nc 3
nop 1
crap 4
1
<?php
2
3
namespace Recurrence\Rrule\Transformer;
4
5
use Recurrence\Rrule\Extractor\UntilTimezonedExtractor;
6
use Recurrence\Model\Exception\InvalidRruleException;
7
8
/**
9
 * Class UntilTimezonedTransformer
10
 * @package Recurrence\Rrule\Transformer
11
 */
12
class UntilTimezonedTransformer extends DtStartTimezonedTransformer
13
{
14
    /**
15
     * @param array $values
16
     * @return \DateTime
17
     * @throws InvalidRruleException
18
     */
19
    public function transform(array $values)
20
    {
21 1
        $this->validate($values);
22
23
        try {
24 1
            return parent::transform($values);
25 1
        } catch (InvalidRruleException $e) {
26 1
            throw new InvalidRruleException(UntilTimezonedExtractor::RRULE_PARAMETER, implode(', ', $values));
27
        }
28
    }
29
30
    /**
31
     * @param array $values
32
     * @throws InvalidRruleException
33
     */
34
    protected function validate(array $values)
35
    {
36 1
        if (!isset($values[0]) || !isset($values[1])) {
37 1
            throw new InvalidRruleException(UntilTimezonedExtractor::RRULE_PARAMETER);
38
        }
39
40
        try {
41 1
            new \DateTimeZone($values[0]);
42 1
        } catch (\Exception $e) {
43 1
            throw new InvalidRruleException(UntilTimezonedExtractor::RRULE_PARAMETER, (string) $values[0]);
44
        }
45 1
    }
46
}
47