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

InventoryClient   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 69
ccs 0
cts 24
cp 0
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A getLocations() 0 7 1
A getLocation() 0 7 1
A getProduct() 0 7 1
A getHistory() 0 7 1
A getSettings() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\IzettleApi\Client;
6
7
use LauLamanApps\IzettleApi\IzettleClientInterface;
8
use Ramsey\Uuid\UuidInterface;
9
10
final class InventoryClient
11
{
12
    const BASE_URL = 'https://inventory.izettle.com/organizations/%s';
13
14
    const GET_HISTORY = self::BASE_URL . '/history/locations/%s';
15
16
    const GET_PRODUCT_INVENTORY = self::BASE_URL . '/inventory/locations/%s/products/%s';
17
    const GET_LOCATION_INVENTORY = self::BASE_URL . '/inventory/locations/%s';
18
    const POST_INVENTORY = self::BASE_URL . '/inventory';
19
    const POST_INVENTORY_BULK = self::BASE_URL . '/inventory/bulk';
20
    const PUT_INVENTORY = self::BASE_URL . '/inventory';
21
    const DELETE_PRODUCT_INVENTORY = self::BASE_URL . '/inventory/products/%s';
22
23
    const GET_LOCATIONS = self::BASE_URL . '/locations';
24
    const PUT_LOCATIONS = self::BASE_URL . '/locations/%s';
25
26
    const GET_SETTINGS = self::BASE_URL . '/settings';
27
    const POST_SETTINGS = self::BASE_URL . '/settings';
28
    const PUT_SETTINGS = self::BASE_URL . '/settings';
29
30
    private $client;
31
    private $organizationUuid;
32
33
    public function __construct(IzettleClientInterface $client, ?UuidInterface $organizationUuid = null)
34
    {
35
        $this->client = $client;
36
        $this->organizationUuid = $organizationUuid ? (string) $organizationUuid : 'self';
37
    }
38
39
    public function getLocations()
40
    {
41
        $url = sprintf(self::GET_LOCATIONS, $this->organizationUuid);
42
        $json = $this->client->getJson($this->client->get($url));
43
44
        return $this->purchaseHistoryBuilder->buildFromJson($json);
0 ignored issues
show
Bug introduced by
The property purchaseHistoryBuilder does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
45
    }
46
47
    public function getLocation(UuidInterface $locationUuid)
48
    {
49
        $url = sprintf(self::GET_LOCATION_INVENTORY, $this->organizationUuid, (string) $locationUuid);
50
        $json = $this->client->getJson($this->client->get($url));
51
52
        return $this->purchaseHistoryBuilder->buildFromJson($json);
53
    }
54
55
    public function getProduct(UuidInterface $locationUuid, UuidInterface $productUuid)
56
    {
57
        $url = sprintf(self::GET_PRODUCT_INVENTORY, $this->organizationUuid, (string) $locationUuid, (string) $productUuid);
58
        $json = $this->client->getJson($this->client->get($url));
59
60
        return $this->purchaseHistoryBuilder->buildFromJson($json);
61
    }
62
63
    public function getHistory(UuidInterface $locationUuid)
64
    {
65
        $url = sprintf(self::GET_HISTORY, $this->organizationUuid, (string) $locationUuid);
66
        $json = $this->client->getJson($this->client->get($url, ['balanceChangeType' => 'RESTOCK']));
67
68
        return $this->purchaseHistoryBuilder->buildFromJson($json);
69
    }
70
71
    public function getSettings()
72
    {
73
        $url = sprintf(self::GET_SETTINGS, $this->organizationUuid);
74
        $json = $this->client->getJson($this->client->get($url));
75
76
        return $this->purchaseHistoryBuilder->buildFromJson($json);
77
    }
78
}
79