Completed
Push — master ( 4fc9ff...a9510e )
by Samuel
02:16
created

FreqTransformer::transform()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 1
crap 3
1
<?php
2
3
namespace Recurrence\RruleTransformer;
4
5
use Recurrence\Frequency;
6
7
/**
8
 * Class FreqTransformer
9
 * @package Recurrence\RruleTransformer
10
 */
11
class FreqTransformer implements TransformerInterface
12
{
13
    /**
14
     * @param string $rRule
15
     * @return Frequency
16
     */
17
    public function transform($rRule)
18
    {
19 1
        if (preg_match('/FREQ=([a-zA-Z]+)/', $rRule, $matches)) {
20 1
            return new Frequency($matches[1]);
21
        }
22
23
        // If there is a FREQ option but transformer was not able to get it, assume it was an invalid option
24 1
        if (preg_match('/FREQ=/', $rRule, $matches)) {
25 1
            throw new \InvalidArgumentException('RRULE invalid [FREQ] option');
26
        }
27
28 1
        throw new \InvalidArgumentException('RRULE required [FREQ] option');
29
    }
30
}
31