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

ProductCollection   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 33
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A add() 0 4 1
A remove() 0 4 1
A get() 0 4 1
A getAll() 0 4 1
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 ProductCollection
10
{
11
    /** @var Product[] */
12
    private $collection = [];
13
14 3
    public function __construct(?array $products = [])
15
    {
16 3
        foreach ($products as $product) {
17 1
            $this->add($product);
18
        }
19 3
    }
20
21 2
    public function add(Product $product): void
22
    {
23 2
        $this->collection[(string) $product->getUuid()] = $product;
24 2
    }
25
26 1
    public function remove(Product $product): void
27
    {
28 1
        unset($this->collection[(string) $product->getUuid()]);
29 1
    }
30
31 1
    public function get(UuidInterface $key): Product
32
    {
33 1
        return $this->collection[(string) $key];
34
    }
35
36
    /** @return Product[] */
37 2
    public function getAll(): array
38
    {
39 2
        return $this->collection;
40
    }
41
}
42