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

VariantBuilder   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 29
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A buildFromArray() 0 10 2
A build() 0 15 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\IzettleApi\Client\Product;
6
7
use LauLamanApps\IzettleApi\API\Product\Variant;
8
use LauLamanApps\IzettleApi\API\Product\VariantCollection;
9
use Money\Currency;
10
use Money\Money;
11
use Ramsey\Uuid\Uuid;
12
13
final class VariantBuilder implements VariantBuilderInterface
14
{
15 4
    public function buildFromArray(array $data): VariantCollection
16
    {
17 4
        $collection = new VariantCollection();
18
19 4
        foreach ($data as $variant) {
20 4
            $collection->add($this->build($variant));
21
        }
22
23 4
        return $collection;
24
    }
25
26 4
    private function build(array $data): Variant
27
    {
28 4
        return Variant::create(
29 4
            Uuid::fromString($data['uuid']),
30 4
            $data['name'],
31 4
            $data['description'],
32 4
            $data['sku'],
33 4
            $data['barcode'],
34 4
            (int) $data['defaultQuantity'],
35 4
            $data['unitName'],
36 4
            new Money($data['price']['amount'], new Currency($data['price']['currencyId'])),
37 4
            $data['costPrice'] ? new Money($data['costPrice']['amount'], new Currency($data['costPrice']['currencyId'])) : null,
38 4
            (float) $data['vatPercentage']
39
        );
40
    }
41
}
42