Passed
Push — master ( ed2711...5bfb66 )
by Samuel
02:22
created

AbstractExtractor   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

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
/**
8
 * Class AbstractExtractor
9
 * @package Recurrence\Rrule\Model
10
 */
11
abstract class AbstractExtractor implements RruleExtractorInterface
12
{
13
    /**
14
     * @param string $rRule
15
     * @throws InvalidRruleException
16
     * @return array|null
17
     */
18
    public function extract($rRule)
19
    {
20 1
        if (preg_match(sprintf('/%s=%s/', $this::RRULE_PARAMETER, $this::RRULE_PATTERN), $rRule, $matches)) {
0 ignored issues
show
Bug introduced by
The constant Recurrence\Rrule\Extract...xtractor::RRULE_PATTERN was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant Recurrence\Rrule\Extract...ractor::RRULE_PARAMETER was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
21 1
            return array_slice($matches, 1);
22
        }
23
24 1
        $this->throwExceptionOnInvalidParameter($rRule, $this::RRULE_PARAMETER);
25
26 1
        return null;
27
    }
28
29
    /**
30
     * @param string $rRule
31
     * @param string $ruleKey
32
     * @throws InvalidRruleException
33
     * @return void
34
     */
35
    public function throwExceptionOnInvalidParameter($rRule, $ruleKey)
36
    {
37 1
        if ((preg_match(sprintf('/%s=([\d\w]+)/', $ruleKey), $rRule, $matches) === 1)) {
38 1
            throw new InvalidRruleException($ruleKey, ((count($matches) > 0)? implode(', ', array_slice($matches, 1)) : ''));
39
        }
40 1
    }
41
}
42