Passed
Branch releases/1.0-dev (6a4c8c)
by Laurens
03:03
created

Variant::getVat()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\IzettleApi\API\Product;
6
7
use LauLamanApps\IzettleApi\API\Universal\Vat;
8
use Money\Money;
9
use Ramsey\Uuid\Uuid;
10
use Ramsey\Uuid\UuidInterface;
11
12
final class Variant
13
{
14
15
    /**
16
     * @var UuidInterface
17
     */
18
    private $uuid;
19
20
    /**
21
     * @var string|null
22
     */
23
    private $name;
24
25
    /**
26
     * @var string|null
27
     */
28
    private $description;
29
30
    /**
31
     * @var string|null
32
     */
33
    private $sku;
34
35
    /**
36
     * @var string|null
37
     */
38
    private $barcode;
39
40
    /**
41
     * @var int
42
     */
43
    private $defaultQuantity;
44
45
    /**
46
     * @var string|null
47
     */
48
    private $unitName;
49
50
    /**
51
     * @var Money
52
     */
53
    private $price;
54
55
    /**
56
     * @var Money|null
57
     */
58
    private $costPrice;
59
60
    /**
61
     * @var Vat|null
62
     */
63
    private $vat;
64
65
66 4
    public static function create(
67
        UuidInterface $uuid,
68
        ?string $name = null,
69
        ?string $description = null,
70
        ?string $sku = null,
71
        ?string $barcode = null,
72
        int $defaultQuantity,
73
        ?string $unitName = null,
74
        Money $price,
75
        ?Money $costPrice = null,
76
        ?Vat $vat = null
77
    ): self {
78 4
        return new self(
79 4
            $uuid,
80 4
            $name,
81 4
            $description,
82 4
            $sku,
83 4
            $barcode,
84 4
            $defaultQuantity,
85 4
            $unitName,
86 4
            $price,
87 4
            $costPrice,
88 4
            $vat
89
        );
90
    }
91
92 3
    public static function new(
93
        ?string $name = null,
94
        ?string $description = null,
95
        ?string $sku = null,
96
        ?string $barcode = null,
97
        int $defaultQuantity,
98
        ?string $unitName = null,
99
        Money $price,
100
        ?Money $costPrice = null,
101
        ?Vat $vat = null
102
    ): self {
103 3
        return new self(
104 3
            Uuid::uuid1(),
105 3
            $name,
106 3
            $description,
107 3
            $sku,
108 3
            $barcode,
109 3
            $defaultQuantity,
110 3
            $unitName,
111 3
            $price,
112 3
            $costPrice,
113 3
            $vat
114
        );
115
    }
116
117 9
    public function getUuid(): UuidInterface
118
    {
119 9
        return $this->uuid;
120
    }
121
122 4
    public function getName(): ?string
123
    {
124 4
        return $this->name;
125
    }
126
127 4
    public function getDescription(): ?string
128
    {
129 4
        return $this->description;
130
    }
131
132 4
    public function getSku(): ?string
133
    {
134 4
        return $this->sku;
135
    }
136
137 4
    public function getBarcode(): ?string
138
    {
139 4
        return $this->barcode;
140
    }
141
142 4
    public function getDefaultQuantity(): ?int
143
    {
144 4
        return $this->defaultQuantity;
145
    }
146
147 4
    public function getUnitName(): ?string
148
    {
149 4
        return $this->unitName;
150
    }
151
152 2
    public function getPrice(): Money
153
    {
154 2
        return $this->price;
155
    }
156
157 2
    public function getCostPrice(): ?Money
158
    {
159 2
        return $this->costPrice;
160
    }
161
162 4
    public function getVat(): ?Vat
163
    {
164 4
        return $this->vat;
165
    }
166
167 2
    public function getCreateDataArray(): array
168
    {
169
        $data = [
170 2
            'uuid' => $this->getUuid(),
171 2
            'name' => $this->getName(),
172 2
            'description' => $this->getDescription(),
173 2
            'sku' => $this->getSku(),
174 2
            'barcode' => $this->getBarcode(),
175 2
            'defaultQuantity' => $this->getDefaultQuantity(),
176 2
            'unitName' => $this->getUnitName(),
177
            'price' => [
178 2
                'amount' => $this->price->getAmount(),
179 2
                'currencyId' => (string) $this->price->getCurrency(),
180
            ],
181 2
            'vatPercentage' => $this->getVat() ? $this->getVat()->getPercentage() : '0'
182
        ];
183
184 2
        if ($this->costPrice) {
185 1
            $data['costPrice'] =[
186 1
                'amount' => $this->costPrice->getAmount(),
187 1
                'currencyId' => (string) $this->costPrice->getCurrency()
188
            ];
189
        }
190
191 2
        return $data;
192
    }
193
194 7
    private function __construct(
195
        UuidInterface $uuid,
196
        ?string $name,
197
        ?string $description,
198
        ?string $sku,
199
        ?string $barcode,
200
        int $defaultQuantity,
201
        ?string $unitName,
202
        Money $price,
203
        ?Money $costPrice,
204
        ?Vat $vat = null
205
    ) {
206 7
        $this->uuid = $uuid;
207 7
        $this->name = $name;
208 7
        $this->description = $description;
209 7
        $this->sku = $sku;
210 7
        $this->barcode = $barcode;
211 7
        $this->defaultQuantity = $defaultQuantity;
212 7
        $this->unitName = $unitName;
213 7
        $this->price = $price;
214 7
        $this->costPrice = $costPrice;
215 7
        $this->vat = $vat;
216 7
    }
217
}
218