Completed
Push — master ( 168b8f...f2b799 )
by Tobias
02:41
created

ReminderCollection   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 81.25%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 45
ccs 13
cts 16
cp 0.8125
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A createFromArray() 0 11 3
A getReminders() 0 4 1
A toArray() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Billogram\Model\Invoice;
6
7
use Billogram\Model\CreatableFromArray;
8
9
/**
10
 * @author Ibrahim Hizeoui <[email protected]>
11
 */
12
class ReminderCollection implements CreatableFromArray
13
{
14
    /**
15
     * @var AutomaticReminder[]
16
     */
17
    private $reminders;
18
19
    /**
20
     * @param AutomaticReminder[] $reminders
21
     */
22 5
    public function __construct(array $reminders)
23
    {
24 5
        $this->reminders = $reminders;
25 5
    }
26
27 5
    public static function createFromArray(array $data)
28
    {
29 5
        $reminders = [];
30 5
        if (isset($data['data'])) {
31
            foreach ($data['data'] as $item) {
32
                $reminders[] = AutomaticReminder::createFromArray(['data' => $item]);
33
            }
34
        }
35
36 5
        return new self($reminders);
37
    }
38
39
    /**
40
     * @return AutomaticReminder[]
41
     */
42 1
    public function getReminders(): array
43
    {
44 1
        return $this->reminders;
45
    }
46
47 1
    public function toArray()
48
    {
49 1
        $reminders = [];
50 1
        foreach ($this->getReminders() as $r) {
51
            $reminders[] = $r->toArray();
52
        }
53
54 1
        return $reminders;
55
    }
56
}
57