Completed
Push — master ( 474cbc...4e1719 )
by Olivier
03:46
created

RecurrenceRule::getLastEvent()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.0416

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 5
cts 6
cp 0.8333
rs 9.8666
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3.0416

1 Method

Rating   Name   Duplication   Size   Complexity  
A RecurrenceRule::getParts() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shapin\Calendar\Model;
6
7
class RecurrenceRule
8
{
9
    private $parts;
10
11 8
    private function __construct()
12
    {
13 8
    }
14
15 8
    public static function createFromArray(array $parts): self
16
    {
17 8
        if (array_key_exists('UNTIL', $parts) && is_string($parts['UNTIL'])) {
18 2
            $parts['UNTIL'] = new \DateTimeImmutable($parts['UNTIL']);
19
        }
20
21 8
        $rule = new self();
22 8
        $rule->parts = $parts;
23
24 8
        return $rule;
25
    }
26
27
    public function getModifier(int $times = 1): string
28
    {
29
        if (!isset($this->parts['FREQ'])) {
30
            throw new \BadMethodCallException("RecurrenceRule doesn't contains a FREQ. Not implemented yet.");
31
        }
32
33
        $freq = $this->parts['FREQ'];
34
35
        if ('WEEKLY' === $freq) {
36
            return "+$times week";
37
        }
38
        if ('MONTHLY' === $freq) {
39
            return "+$times month";
40
        }
41
42
        throw new \BadMethodCallException("Unknown freq $freq");
43
    }
44
45 8
    public function getParts(): array
46
    {
47 8
        return $this->parts;
48
    }
49
}
50