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

PurchaseHistoryBuilder   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 20
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A buildFromJson() 0 10 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