Completed
Pull Request — master (#18)
by Samuel
03:55
created

UntilTransformer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

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