UntilTimezonedTransformer   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 12
dl 0
loc 29
ccs 9
cts 9
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A transform() 0 8 2
A validate() 0 10 4
1
<?php
2
3
namespace Recurrence\Rrule\Transformer;
4
5
use Recurrence\Rrule\Extractor\UntilTimezonedExtractor;
6
use Recurrence\Model\Exception\InvalidRruleException;
7
8
class UntilTimezonedTransformer extends DtStartTimezonedTransformer
9
{
10
    /**
11
     * @throws InvalidRruleException
12
     */
13
    public function transform(array $values): \DateTime
14
    {
15 1
        $this->validate($values);
16
17
        try {
18 1
            return parent::transform($values);
19 1
        } catch (InvalidRruleException $e) {
20 1
            throw new InvalidRruleException(UntilTimezonedExtractor::RRULE_PARAMETER, implode(', ', $values));
21
        }
22
    }
23
24
    /**
25
     * @throws InvalidRruleException
26
     */
27
    protected function validate(array $values): void
28
    {
29 1
        if (!isset($values[0]) || !isset($values[1])) {
30 1
            throw new InvalidRruleException(UntilTimezonedExtractor::RRULE_PARAMETER);
31
        }
32
33
        try {
34 1
            new \DateTimeZone($values[0]);
35 1
        } catch (\Exception $e) {
36 1
            throw new InvalidRruleException(UntilTimezonedExtractor::RRULE_PARAMETER, (string) $values[0]);
37
        }
38 1
    }
39
}
40