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

LibraryParser::createFromResponse()   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 LibraryParser
12
{
13 2
    public static function createFromResponse(ResponseInterface $response): Library
14
    {
15 2
        $data = json_decode($response->getBody()->getContents(), true);
16
17 2
        return new Library(
18 2
            Uuid::fromString($data['fromEventLogUuid']),
19 2
            Uuid::fromString($data['untilEventLogUuid']),
20 2
            ProductParser::parseArray($data['products']),
21 2
            DiscountParser::parseArray($data['discounts']),
22 2
            ProductParser::parseArray($data['deletedProducts']),
23 2
            DiscountParser::parseArray($data['deletedDiscounts'])
24
        );
25
    }
26
}
27