AbstractExtractor   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 9
dl 0
loc 26
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A throwExceptionOnInvalidParameter() 0 4 3
A extract() 0 9 2
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