Completed
Pull Request — master (#16)
by Samuel
02:09
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
     * @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