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

throwExceptionOnInvalidParameter()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 2
eloc 3
nc 2
nop 2
crap 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