Completed
Pull Request — master (#11)
by Laurens
02:39 queued 51s
created

PurchaseHistoryBuilder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\IzettleApi\Client\Purchase;
6
7
use LauLamanApps\IzettleApi\API\Purchase\PurchaseHistory;
8
use Psr\Http\Message\ResponseInterface;
9
10
final class PurchaseHistoryBuilder implements PurchaseHistoryBuilderInterface
11
{
12
    private $purchaseBuilder;
13
14 4
    public function __construct(PurchaseBuilderInterface $purchaseBuilder)
15
    {
16 4
        $this->purchaseBuilder = $purchaseBuilder;
17 4
    }
18
19 2
    public function buildFromJson(string $jsonData): PurchaseHistory
20
    {
21 2
        $data =  json_decode($jsonData, true);
22
23 2
        return new PurchaseHistory(
24 2
            $data['firstPurchaseHash'],
25 2
            $data['lastPurchaseHash'],
26 2
            $this->purchaseBuilder->buildFromArray($data['purchases'])
27
        );
28
    }
29
}
30