Passed
Branch factorize (4cfa74)
by Samuel
01:51
created

CountTransformer::transform()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 2
cts 2
cp 1
rs 9.4285
cc 1
eloc 3
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 View Code Duplication
        if (!isset($values[0]) || !is_numeric($values[0])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
33 1
            throw new InvalidRruleException(CountExtractor::RRULE_PARAMETER, ((isset($values[0]))? (string) $values[0] : ''));
34
        }
35 1
    }
36
}
37