RecurrenceRule::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 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
        $rule = new self();
18 8
        $rule->parts = $parts;
19
20 8
        return $rule;
21
    }
22
23
    public function getModifier(int $times = 1): string
24
    {
25
        if (!isset($this->parts['FREQ'])) {
26
            throw new \BadMethodCallException("RecurrenceRule doesn't contains a FREQ. Not implemented yet.");
27
        }
28
29
        $freq = $this->parts['FREQ'];
30
31
        if ('WEEKLY' === $freq) {
32
            return "+$times week";
33
        }
34
        if ('MONTHLY' === $freq) {
35
            return "+$times month";
36
        }
37
38
        throw new \BadMethodCallException("Unknown freq $freq");
39
    }
40
41 8
    public function getParts(): array
42
    {
43 8
        return $this->parts;
44
    }
45
}
46