RecurrenceRule   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 47.06%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 39
ccs 8
cts 17
cp 0.4706
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A createFromArray() 0 7 1
A getModifier() 0 17 4
A 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
        $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