Passed
Push — master ( 9ff768...b736eb )
by Laurens
02:33
created

Variant   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 165
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 15
lcom 2
cbo 2
dl 0
loc 165
ccs 72
cts 72
cp 1
rs 10
c 0
b 0
f 0

14 Methods

Rating   Name   Duplication   Size   Complexity  
B create() 0 25 1
B new() 0 24 1
A getUuid() 0 4 1
A getName() 0 4 1
A getDescription() 0 4 1
A getSku() 0 4 1
A getBarcode() 0 4 1
A getDefaultQuantity() 0 4 1
A getUnitName() 0 4 1
A getPrice() 0 4 1
A getCostPrice() 0 4 1
A getVatPercentage() 0 4 1
B getCreateDataArray() 0 26 2
A __construct() 0 23 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\IzettleApi\API\Product;
6
7
use Money\Money;
8
use Ramsey\Uuid\Uuid;
9
use Ramsey\Uuid\UuidInterface;
10
11
final class Variant
12
{
13
    private $uuid;
14
    private $name;
15
    private $description;
16
    private $sku;
17
    private $barcode;
18
    private $defaultQuantity;
19
    private $unitName;
20
    private $price;
21
    private $costPrice;
22
    private $vatPercentage;
23
24 3
    public static function create(
25
        UuidInterface $uuid,
26
        ?string $name = null,
27
        ?string $description = null,
28
        ?string $sku = null,
29
        ?string $barcode = null,
30
        int $defaultQuantity,
31
        ?string $unitName = null,
32
        Money $price,
33
        ?Money $costPrice = null,
34
        float $vatPercentage
35
    ): self {
36 3
        return new self(
37 3
            $uuid,
38 3
            $name,
39 3
            $description,
40 3
            $sku,
41 3
            $barcode,
42 3
            $defaultQuantity,
43 3
            $unitName,
44 3
            $price,
45 3
            $costPrice,
46 3
            $vatPercentage
47
        );
48
    }
49
50 3
    public static function new(
51
        ?string $name = null,
52
        ?string $description = null,
53
        ?string $sku = null,
54
        ?string $barcode = null,
55
        int $defaultQuantity,
56
        ?string $unitName = null,
57
        Money $price,
58
        ?Money $costPrice = null,
59
        float $vatPercentage
60
    ): self {
61 3
        return new self(
62 3
            Uuid::uuid1(),
63 3
            $name,
64 3
            $description,
65 3
            $sku,
66 3
            $barcode,
67 3
            $defaultQuantity,
68 3
            $unitName,
69 3
            $price,
70 3
            $costPrice,
71 3
            $vatPercentage
72
        );
73
    }
74
75 8
    public function getUuid(): UuidInterface
76
    {
77 8
        return $this->uuid;
78
    }
79
80 5
    public function getName(): ?string
81
    {
82 5
        return $this->name;
83
    }
84
85 5
    public function getDescription(): ?string
86
    {
87 5
        return $this->description;
88
    }
89
90 5
    public function getSku(): ?string
91
    {
92 5
        return $this->sku;
93
    }
94
95 5
    public function getBarcode(): ?string
96
    {
97 5
        return $this->barcode;
98
    }
99
100 5
    public function getDefaultQuantity(): ?int
101
    {
102 5
        return $this->defaultQuantity;
103
    }
104
105 5
    public function getUnitName(): ?string
106
    {
107 5
        return $this->unitName;
108
    }
109
110 2
    public function getPrice(): Money
111
    {
112 2
        return $this->price;
113
    }
114
115 2
    public function getCostPrice(): ?Money
116
    {
117 2
        return $this->costPrice;
118
    }
119
120 5
    public function getVatPercentage(): float
121
    {
122 5
        return $this->vatPercentage;
123
    }
124
125 3
    public function getCreateDataArray(): array
126
    {
127
        $data = [
128 3
            'uuid' => $this->getUuid(),
129 3
            'name' => $this->getName(),
130 3
            'description' => $this->getDescription(),
131 3
            'sku' => $this->getSku(),
132 3
            'barcode' => $this->getBarcode(),
133 3
            'defaultQuantity' => $this->getDefaultQuantity(),
134 3
            'unitName' => $this->getUnitName(),
135
            'price' => [
136 3
                'amount' => $this->price->getAmount(),
137 3
                'currencyId' => (string) $this->price->getCurrency(),
138
            ],
139 3
            'vatPercentage' => $this->getVatPercentage()
140
        ];
141
142 3
        if ($this->costPrice) {
143 1
            $data['costPrice'] =[
144 1
                'amount' => $this->costPrice->getAmount(),
145 1
                'currencyId' => (string) $this->costPrice->getCurrency()
146
            ];
147
        }
148
149 3
        return $data;
150
    }
151
152 6
    private function __construct(
153
        UuidInterface $uuid,
154
        ?string $name,
155
        ?string $description,
156
        ?string $sku,
157
        ?string $barcode,
158
        int $defaultQuantity,
159
        ?string $unitName,
160
        Money $price,
161
        ?Money $costPrice,
162
        float $vatPercentage
163
    ) {
164 6
        $this->uuid = $uuid;
165 6
        $this->name = $name;
166 6
        $this->description = $description;
167 6
        $this->sku = $sku;
168 6
        $this->barcode = $barcode;
169 6
        $this->defaultQuantity = $defaultQuantity;
170 6
        $this->unitName = $unitName;
171 6
        $this->price = $price;
172 6
        $this->costPrice = $costPrice;
173 6
        $this->vatPercentage = $vatPercentage;
174 6
    }
175
}
176