Completed
Pull Request — master (#21)
by
unknown
08:19 queued 05:22
created

Variant::getBarcode()   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 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 4
    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 4
        return new self(
37 4
            $uuid,
38 4
            $name,
39 4
            $description,
40 4
            $sku,
41 4
            $barcode,
42 4
            $defaultQuantity,
43 4
            $unitName,
44 4
            $price,
45 4
            $costPrice,
46 4
            $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 9
    public function getUuid(): UuidInterface
76
    {
77 9
        return $this->uuid;
78
    }
79
80 4
    public function getName(): ?string
81
    {
82 4
        return $this->name;
83
    }
84
85 4
    public function getDescription(): ?string
86
    {
87 4
        return $this->description;
88
    }
89
90 4
    public function getSku(): ?string
91
    {
92 4
        return $this->sku;
93
    }
94
95 4
    public function getBarcode(): ?string
96
    {
97 4
        return $this->barcode;
98
    }
99
100 4
    public function getDefaultQuantity(): ?int
101
    {
102 4
        return $this->defaultQuantity;
103
    }
104
105 4
    public function getUnitName(): ?string
106
    {
107 4
        return $this->unitName;
108
    }
109
110 2
    public function getPrice(): Money
111
    {
112 2
        return $this->price;
113
    }
114
115
    public function getCostPrice(): ?Money
116
    {
117
        return $this->costPrice;
118
    }
119
120 2
    public function getVatPercentage(): float
121
    {
122 2
        return $this->vatPercentage;
123
    }
124
125 2
    public function getCreateDataArray(): array
126
    {
127
        $data = [
128 2
            'uuid' => $this->getUuid(),
129 2
            'name' => $this->getName(),
130 2
            'description' => $this->getDescription(),
131 2
            'sku' => $this->getSku(),
132 2
            'barcode' => $this->getBarcode(),
133 2
            'defaultQuantity' => $this->getDefaultQuantity(),
134 2
            'unitName' => $this->getUnitName(),
135
            'price' => [
136 2
                'amount' => $this->price->getAmount(),
137 2
                'currencyId' => (string) $this->price->getCurrency(),
138
            ],
139 2
            'vatPercentage' => $this->getVatPercentage()
140
        ];
141
142 2
        if ($this->costPrice) {
143 1
            $data['costPrice'] =[
144 1
                'amount' => $this->costPrice->getAmount(),
145 1
                'currencyId' => (string) $this->costPrice->getCurrency()
146
            ];
147
        }
148
149 2
        return $data;
150
    }
151
152 7
    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 7
        $this->uuid = $uuid;
165 7
        $this->name = $name;
166 7
        $this->description = $description;
167 7
        $this->sku = $sku;
168 7
        $this->barcode = $barcode;
169 7
        $this->defaultQuantity = $defaultQuantity;
170 7
        $this->unitName = $unitName;
171 7
        $this->price = $price;
172 7
        $this->costPrice = $costPrice;
173 7
        $this->vatPercentage = $vatPercentage;
174 7
    }
175
}
176