Completed
Pull Request — master (#16)
by Samuel
01:56
created

AbstractRruleTransformer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
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 29
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
     * @return integer
15
     */
16
    public function transform($rRule)
17
    {
18 1
        if (preg_match(sprintf('/%s=%s/', $this::RRULE_PARAMETER, $this::RRULE_PATTERN), $rRule, $matches)) {
19 1
            return (is_numeric($matches[1])) ? (int) $matches[1] : $matches[1];
20
        }
21
22 1
        $this->throwExceptionOnInvalidParameter($rRule, $this::RRULE_PARAMETER);
23
24 1
        return null;
25
    }
26
27
    /**
28
     * @param string $rRule
29
     * @param string $ruleKey
30
     * @return bool
31
     */
32
    public function throwExceptionOnInvalidParameter($rRule, $ruleKey)
33
    {
34 1
        if ((preg_match(sprintf('/%s=/', $ruleKey), $rRule, $matches) === 1)) {
35 1
            throw new \InvalidArgumentException(sprintf('RRULE invalid [%s] option', $ruleKey));
36
        }
37 1
    }
38
}
39