Completed
Push — master ( 2855c4...4fc9ff )
by Samuel
02:27
created

FreqTransformer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 0
cbo 1
dl 0
loc 20
ccs 4
cts 5
cp 0.8
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 13 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
            throw new \InvalidArgumentException('RRULE invalid [FREQ] option');
26
        }
27
28 1
        throw new \InvalidArgumentException('RRULE required [FREQ] option');
29
    }
30
}
31