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

CategoryCollection::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\IzettleApi\API\Product;
6
7
use Ramsey\Uuid\UuidInterface;
8
9
final class CategoryCollection
10
{
11
    /** @var Category[] */
12
    private $collection = [];
13
14 9
    public function __construct(?array $categories = [])
15
    {
16 9
        foreach ($categories as $category) {
17 1
            $this->add($category);
18
        }
19 9
    }
20
21 3
    public function add(Category $category): void
22
    {
23 3
        $this->collection[(string) $category->getUuid()] = $category;
24 3
    }
25
26 1
    public function remove(Category $category): void
27
    {
28 1
        unset($this->collection[(string)$category->getUuid()]);
29 1
    }
30
31 1
    public function get(UuidInterface $key): Category
32
    {
33 1
        return $this->collection[(string)$key];
34
    }
35
36
    /** @return Category[] */
37 3
    public function getAll(): array
38
    {
39 3
        return $this->collection;
40
    }
41
42 3
    public function getCreateDataArray(): array
43
    {
44 3
        $data = [];
45 3
        foreach ($this->collection as $category) {
46 1
            $data[] = $category->getUuid();
47
        }
48
49 3
        return $data;
50
    }
51
}
52