Completed
Push — master ( a67fbc...6c0a08 )
by Samuel
11s
created

RecurrenceProvider::parse()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 20
rs 9.2
cc 4
eloc 10
nc 5
nop 1
1
<?php
2
3
namespace Recurrence;
4
5
use Recurrence\RruleTransformer\DtStartTransformer;
6
use Recurrence\RruleTransformer\FreqTransformer;
7
use Recurrence\RruleTransformer\UntilTransformer;
8
9
class RecurrenceProvider
10
{
11
12
    public function __construct()
13
    {
14
        $this->freqTransformer    = new FreqTransformer();
0 ignored issues
show
Bug introduced by
The property freqTransformer does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
15
        $this->dtStartTransformer = new DtStartTransformer();
0 ignored issues
show
Bug introduced by
The property dtStartTransformer does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
16
        $this->untilTransformer   = new UntilTransformer();
0 ignored issues
show
Bug introduced by
The property untilTransformer does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
17
    }
18
19
    /**
20
     * @param string $rRule
21
     * @return Recurrence
22
     * @throws \InvalidArgumentException
23
     */
24
    public function parse($rRule)
25
    {
26
        if (empty($rRule)) {
27
            throw new \InvalidArgumentException('Empty RRULE');
28
        }
29
30
        $recurrence = new Recurrence();
31
32
        $recurrence->setFrequency($this->freqTransformer->transform($rRule));
33
34
        if ($periodStartAt = $this->dtStartTransformer->transform($rRule)) {
35
            $recurrence->setPeriodStartAt($periodStartAt);
36
        }
37
38
        if ($periodStartAt = $this->untilTransformer->transform($rRule)) {
39
            $recurrence->setPeriodEndAt($periodStartAt);
40
        }
41
42
        return $recurrence;
43
    }
44
45
}