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

ImageBuilder::buildFromJson()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\IzettleApi\Client\Universal;
6
7
use LauLamanApps\IzettleApi\API\Image;
8
use LauLamanApps\IzettleApi\API\ImageCollection;
9
10
final class ImageBuilder implements ImageBuilderInterface
11
{
12 2
    public function buildFromJson(string $json): Image
13
    {
14 2
        $data = json_decode($json, true);
15
16 2
        return new Image($data['imageLookupKey']);
17
    }
18
19 4
    public function buildFromArray(array $images): ImageCollection
20
    {
21 4
        $collection = new ImageCollection();
22
23 4
        foreach ($images as $image) {
24 3
            $collection->add($this->build($image));
25
        }
26
27 4
        return $collection;
28
    }
29
30 3
    private function build($data): Image
31
    {
32 3
        return new Image($data);
33
    }
34
}
35