PriceCalculatorResult   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 1 Features 0
Metric Value
eloc 16
dl 0
loc 85
ccs 12
cts 12
cp 1
rs 10
c 5
b 1
f 0
wmc 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A toArray() 0 9 2
A getCalculator() 0 3 1
A getVatRate() 0 3 1
A getDiscount() 0 3 1
A getPriceVat() 0 3 1
A getPrice() 0 3 1
A getBasePrice() 0 3 1
A getVat() 0 3 1
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