Completed
Pull Request — master (#11)
by Laurens
02:56 queued 01:11
created

LibraryBuilder::buildFromJson()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

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