Passed
Push — master ( 9ff768...b736eb )
by Laurens
02:33
created

ImageCollection   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 45
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 3
A add() 0 4 1
A remove() 0 4 1
A get() 0 4 1
A getAll() 0 4 1
A getCreateDataArray() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\IzettleApi\API;
6
7
final class ImageCollection
8
{
9
    /** @var Image[]  */
10
    private $collection = [];
11
12 14
    public function __construct(?array $images = [])
13
    {
14 14
        foreach ($images as $image) {
15 2
            if ($image instanceof Image) {
16 2
                $this->add($image);
17
            }
18
        }
19 14
    }
20
21 7
    public function add(Image $image): void
22
    {
23 7
        $this->collection[$image->getFilename()] = $image;
24 7
    }
25
26 1
    public function remove(Image $image): void
27
    {
28 1
        unset($this->collection[$image->getFilename()]);
29 1
    }
30
31 1
    public function get(string $key): Image
32
    {
33 1
        return $this->collection[$key];
34
    }
35
36
    /** @return Image[] */
37 2
    public function getAll(): array
38
    {
39 2
        return $this->collection;
40
    }
41
42 6
    public function getCreateDataArray(): array
43
    {
44 6
        $data = [];
45 6
        foreach ($this->collection as $image) {
46 1
            $data[] = $image->getFilename();
47
        }
48
49 6
        return $data;
50
    }
51
}
52