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

ImageCollection::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
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