Completed
Pull Request — master (#11)
by Laurens
01:46
created

LibraryBuilder   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 0
loc 27
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A buildFromJson() 0 13 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\IzettleApi\Client\Product;
6
7
use LauLamanApps\IzettleApi\API\Product\Library;
8
use Psr\Http\Message\ResponseInterface;
9
use Ramsey\Uuid\Uuid;
10
11
final class LibraryBuilder implements LibraryBuilderInterface
12
{
13
    private $productBuilder;
14
    private $discountBuilder;
15
16 5
    public function __construct(
17
        ProductBuilderInterface $productBuilder,
18
        DiscountBuilderInterface $discountBuilder
19
    ) {
20 5
        $this->productBuilder = $productBuilder;
21 5
        $this->discountBuilder = $discountBuilder;
22 5
    }
23
24 2
    public function buildFromJson(string $json): Library
25
    {
26 2
        $data = json_decode($json, true);
27
28 2
        return new Library(
29 2
            Uuid::fromString($data['fromEventLogUuid']),
30 2
            Uuid::fromString($data['untilEventLogUuid']),
31 2
            $this->productBuilder->buildFromArray($data['products']),
32 2
            $this->discountBuilder->buildFromArray($data['discounts']),
33 2
            $this->productBuilder->buildFromArray($data['deletedProducts']),
34 2
            $this->discountBuilder->buildFromArray($data['deletedDiscounts'])
35
        );
36
    }
37
}
38