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

CountTransformer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 5
c 1
b 0
f 0
dl 0
loc 22
ccs 4
cts 4
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 4 4
A transform() 0 5 1
1
<?php
2
3
namespace Recurrence\Rrule\Transformer;
4
5
use Recurrence\Rrule\Extractor\CountExtractor;
6
use Recurrence\Model\Exception\InvalidRruleException;
7
8
/**
9
 * Class CountTransformer
10
 * @package Recurrence\RruleTransformer
11
 */
12
class CountTransformer implements RruleTransformerInterface
13
{
14
    /**
15
     * @param array $values
16
     * @throws InvalidRruleException
17
     * @return int
18
     */
19
    public function transform(array $values)
20
    {
21 1
        $this->validate($values);
22
23 1
        return (int) $values[0];
24
    }
25
26
    /**
27
     * @param array $values
28
     * @throws InvalidRruleException
29
     */
30
    protected function validate(array $values)
31
    {
32 1
        if (!isset($values[0]) || !is_numeric($values[0])) {
33 1
            throw new InvalidRruleException(CountExtractor::RRULE_PARAMETER, ((isset($values[0]))? (string) $values[0] : ''));
34
        }
35 1
    }
36
}
37