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

DtStartTransformer::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Recurrence\Rrule\Transformer;
4
5
use Recurrence\Rrule\Extractor\DtStartExtractor;
6
use Recurrence\Model\Exception\InvalidRruleException;
7
8
/**
9
 * Class DtStartTransformer
10
 * @package Recurrence\Rrule\Transformer
11
 */
12
class DtStartTransformer implements RruleTransformerInterface
13
{
14
    /**
15
     * @param array $values
16
     * @return \DateTime
17
     * @throws InvalidRruleException
18
     */
19
    public function transform(array $values)
20
    {
21 1
        $this->validate($values);
22
23 1
        $dtStart = null;
0 ignored issues
show
Unused Code introduced by
$dtStart is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
24
25 1
        if (count($values) == 2 && substr($values[1], -1) == 'Z') {
26 1
            $dtStart = \DateTime::createFromFormat('Ymd\THis\Z', $values[0], new \DateTimeZone('UTC'));
27 1
        } else if (count($values) == 2) {
28 1
            $dtStart = \DateTime::createFromFormat('Ymd\THis', $values[0]);
29
        } else {
30 1
            $dtStart = \DateTime::createFromFormat('Ymd', $values[0]);
31
        }
32
33 1
        if (!$dtStart) {
34 1
            throw new InvalidRruleException(DtStartExtractor::RRULE_PARAMETER, (string) $values[0]);
35
        }
36
37 1
        return $dtStart;
38
    }
39
40
    /**
41
     * @param array $values
42
     * @throws InvalidRruleException
43
     */
44
    protected function validate(array $values)
45
    {
46 1
        if (!isset($values[0])) {
47 1
            throw new InvalidRruleException(DtStartExtractor::RRULE_PARAMETER);
48
        }
49 1
    }
50
}
51