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

CountTransformer::transform()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 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