throwExceptionOnInvalidParameter()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 3
nc 2
nop 2
crap 3
1
<?php
2
3
namespace Recurrence\Rrule\Extractor;
4
5
use Recurrence\Model\Exception\InvalidRruleException;
6
7
abstract class AbstractExtractor implements RruleExtractorInterface
8
{
9
    public const RRULE_PARAMETER = '';
10
    public const RRULE_PATTERN = '';
11
12
    /**
13
     * @throws InvalidRruleException
14
     */
15
    public function extract(string $rRule): ?array
16
    {
17 1
        if (preg_match(sprintf('/%s=%s/', $this::RRULE_PARAMETER, $this::RRULE_PATTERN), $rRule, $matches)) {
18 1
            return array_slice($matches, 1);
19
        }
20
21 1
        $this->throwExceptionOnInvalidParameter($rRule, $this::RRULE_PARAMETER);
22
23 1
        return null;
24
    }
25
26
    /**
27
     * @throws InvalidRruleException
28
     */
29
    public function throwExceptionOnInvalidParameter(string $rRule, string $ruleKey): void
30
    {
31 1
        if ((preg_match(sprintf('/%s=([\d\w]+)/', $ruleKey), $rRule, $matches) === 1)) {
32 1
            throw new InvalidRruleException($ruleKey, ((count($matches) > 0) ? implode(', ', array_slice($matches, 1)) : ''));
33
        }
34 1
    }
35
}
36