Completed
Pull Request — master (#11)
by Laurens
02:02
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 2
    public function buildFromArray(array $data): VariantCollection
16
    {
17 2
        $collection = new VariantCollection();
18
19 2
        foreach ($data as $variant) {
20 2
            $collection->add($this->build($variant));
21
        }
22
23 2
        return $collection;
24
    }
25
26 2
    private function build(array $data): Variant
27
    {
28 2
        return Variant::create(
29 2
            Uuid::fromString($data['uuid']),
30 2
            $data['name'],
31 2
            $data['description'],
32 2
            $data['sku'],
33 2
            $data['barcode'],
34 2
            (int) $data['defaultQuantity'],
35 2
            $data['unitName'],
36 2
            new Money($data['price']['amount'], new Currency($data['price']['currencyId'])),
37 2
            $data['costPrice'] ? new Money($data['costPrice']['amount'], new Currency($data['costPrice']['currencyId'])) : null,
38 2
            (float) $data['vatPercentage']
39
        );
40
    }
41
}
42