PriceCalculatorResult::toArray()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 0
dl 0
loc 9
ccs 1
cts 1
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Sunfox\PriceCalculator;
4
5
use Nette\SmartObject;
6
7
/**
8
 * @property IPriceCalculator $calculator
9
 * @property float $basePrice
10
 * @property IDiscount|NULL $discount
11
 * @property float $price
12
 * @property float $vatRate
13
 * @property float $vat
14
 * @property float $priceVat
15
 */
16
final class PriceCalculatorResult
17
{
18
	use SmartObject;
19
20
	public function __construct(
21
		protected IPriceCalculator $calculator,
22
		protected float $basePrice = 0.0,
23
		protected ?IDiscount $discount = null,
24
		protected float $price = 0.0,
25
		protected float $vatRate = 0.0,
26
		protected float $vat = 0.0,
27
		protected float $priceVat = 0.0
28
	) {
29
	}
30
31
	/**
32
	 * Return PriceCalculator instance.
33
	 */
34
	public function getCalculator(): IPriceCalculator
35
	{
36
		return $this->calculator;
37
	}
38
39
	/**
40
	 * Get price without VAT and discount.
41
	 */
42
	public function getBasePrice(): float
43
	{
44
		return $this->basePrice;
45
	}
46
47
	/**
48
	 * Get discount object instance.
49
	 */
50
	public function getDiscount(): ?IDiscount
51
	{
52
		return $this->discount;
53
	}
54
55 1
	/**
56
	 * Get price after discount without VAT.
57
	 */
58
	public function getPrice(): float
59
	{
60
		return $this->price;
61
	}
62
63
	/**
64 1
	 * Get VAT rate in percent.
65 1
	 */
66 1
	public function getVatRate(): float
67 1
	{
68 1
		return $this->vatRate;
69 1
	}
70 1
71 1
	/**
72
	 * Get VAT value.
73
	 */
74
	public function getVat(): float
75
	{
76
		return $this->vat;
77
	}
78 1
79
	/**
80
	 * Get price after discount with VAT.
81
	 */
82
	public function getPriceVat(): float
83
	{
84
		return $this->priceVat;
85
	}
86 1
87
	/**
88
	 * Return all prices as array.
89
	 *
90
	 * @return mixed[]
91
	 */
92
	public function toArray(): array
93
	{
94 1
		return [
95
			'basePrice' => $this->basePrice,
96
			'discount' => $this->discount ? $this->discount->getValue() : 0.0,
97
			'price' => $this->price,
98
			'vatRate' => $this->vatRate,
99
			'vat' => $this->vat,
100
			'priceVat' => $this->priceVat,
101
		];
102 1
	}
103
}
104