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

RecurrenceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 4
dl 0
loc 37
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A parse() 0 20 4
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
}