Completed
Pull Request — master (#16)
by Samuel
02:09
created

AbstractRruleTransformer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 31
ccs 7
cts 7
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A transform() 0 10 3
A throwExceptionOnInvalidParameter() 0 6 2
1
<?php
2
3
namespace Recurrence\RruleTransformer;
4
use Recurrence\Recurrence;
5
6
/**
7
 * Class AbstractRruleTransformer
8
 * @package Recurrence\RruleTransformer
9
 */
10
abstract class AbstractRruleTransformer
11
{
12
    /**
13
     * @param string $rRule
14
     * @throws \InvalidArgumentException
15
     * @return mixed
16
     */
17
    public function transform($rRule)
18
    {
19 1
        if (preg_match(sprintf('/%s=%s/', $this::RRULE_PARAMETER, $this::RRULE_PATTERN), $rRule, $matches)) {
20 1
            return (is_numeric($matches[1])) ? (int) $matches[1] : $matches[1];
21
        }
22
23 1
        $this->throwExceptionOnInvalidParameter($rRule, $this::RRULE_PARAMETER);
24
25 1
        return null;
26
    }
27
28
    /**
29
     * @param string $rRule
30
     * @param string $ruleKey
31
     * @throws \InvalidArgumentException
32
     * @return void
33
     */
34
    public function throwExceptionOnInvalidParameter($rRule, $ruleKey)
35
    {
36 1
        if ((preg_match(sprintf('/%s=/', $ruleKey), $rRule, $matches) === 1)) {
37 1
            throw new \InvalidArgumentException(sprintf('RRULE invalid [%s] option', $ruleKey));
38
        }
39 1
    }
40
}
41