Cancelled
Pull Request — master (#11)
by Laurens
23:42
created

PurchaseClient::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 3
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\IzettleApi\Client;
6
7
use LauLamanApps\IzettleApi\API\Purchase\Purchase;
8
use LauLamanApps\IzettleApi\API\Purchase\PurchaseHistory;
9
use LauLamanApps\IzettleApi\Client\Purchase\PurchaseBuilderInterface;
10
use LauLamanApps\IzettleApi\Client\Purchase\PurchaseHistoryBuilderInterface;
11
use LauLamanApps\IzettleApi\IzettleClientInterface;
12
use Ramsey\Uuid\UuidInterface;
13
14
final class PurchaseClient
15
{
16
    const BASE_URL = 'https://purchase.izettle.com';
17
18
    const GET_PURCHASE = self::BASE_URL . '/purchases/v2/%s';
19
    const GET_PURCHASES = self::BASE_URL . '/purchases/v2';
20
21
    private $client;
22
    private $purchaseHistoryBuilder;
23
    private $purchaseBuilder;
24
25 2
    public function __construct(
26
        IzettleClientInterface $client,
27
        PurchaseHistoryBuilderInterface $purchaseHistoryBuilder,
28
        PurchaseBuilderInterface $purchaseBuilder
29
    ) {
30 2
        $this->client = $client;
31 2
        $this->purchaseHistoryBuilder = $purchaseHistoryBuilder;
32 2
        $this->purchaseBuilder = $purchaseBuilder;
33 2
    }
34
35 1
    public function getPurchaseHistory(): PurchaseHistory
36
    {
37 1
        $json = $this->client->getJson($this->client->get(self::GET_PURCHASES));
38
39 1
        return $this->purchaseHistoryBuilder->buildFromJson($json);
40
    }
41
42 1
    public function getPurchase(UuidInterface $uuid): Purchase
43
    {
44 1
        $json = $this->client->getJson($this->client->get(sprintf(self::GET_PURCHASE, (string) $uuid)));
45
46 1
        return $this->purchaseBuilder->buildFromJson($json);
47
    }
48
}
49