Completed
Push — master ( 510f92...73b08b )
by Laurens
01:58
created

ImageClient   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A postImage() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\IzettleApi\Client;
6
7
use LauLamanApps\IzettleApi\API\Image;
8
use LauLamanApps\IzettleApi\Client\Image\ImageUploadRequestInterface;
9
use LauLamanApps\IzettleApi\Client\Universal\ImageBuilderInterface;
10
use LauLamanApps\IzettleApi\IzettleClientInterface;
11
use Ramsey\Uuid\UuidInterface;
12
13
final class ImageClient
14
{
15
    const BASE_URL = 'https://image.izettle.com/organizations/%s';
16
    const POST_IMAGE = self::BASE_URL . '/products';
17
18
    private $client;
19
    private $organizationUuid = 'self';
20
    private $imageBuilder;
21
22 3
    public function __construct(
23
        IzettleClientInterface $client,
24
        ?UuidInterface $organizationUuid = null,
25
        ImageBuilderInterface $imageBuilder
26
    ) {
27 3
        $this->client = $client;
28 3
        $this->organizationUuid = (string) $organizationUuid;
29 3
        $this->imageBuilder = $imageBuilder;
30 3
    }
31
32 3
    public function postImage(ImageUploadRequestInterface $imageUploadRequest): Image
33
    {
34 3
        $url = sprintf(self::POST_IMAGE, $this->organizationUuid);
35 3
        $data = json_encode($imageUploadRequest->getUploadRequest());
36
37 3
        $response = $this->client->post($url, $data);
38
39 3
        return $this->imageBuilder->buildFromJson($this->client->getJson($response));
40
    }
41
}
42