CollectionItem   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 2
dl 0
loc 40
ccs 12
cts 14
cp 0.8571
rs 10
c 0
b 0
f 0

3 Methods

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