These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php declare(strict_types=1); |
||
2 | |||
3 | namespace Sunfox\PriceCalculator; |
||
4 | |||
5 | use Nette; |
||
6 | |||
7 | |||
8 | /** |
||
9 | * @property IPriceCalculator $calculator |
||
10 | * @property float $basePrice |
||
11 | * @property float $discount |
||
12 | * @property float $price |
||
13 | * @property float $vatRate |
||
14 | * @property float $vat |
||
15 | * @property float $priceVat |
||
16 | */ |
||
17 | class PriceCalculatorResult |
||
18 | { |
||
19 | use Nette\SmartObject; |
||
20 | |||
21 | /** @var IPriceCalculator */ |
||
22 | protected $calculator; |
||
23 | |||
24 | /** @var float */ |
||
25 | protected $basePrice = 0.0; |
||
26 | |||
27 | /** @var float */ |
||
28 | protected $discount = 0.0; |
||
29 | |||
30 | /** @var float */ |
||
31 | protected $price = 0.0; |
||
32 | |||
33 | /** @var float */ |
||
34 | protected $vatRate = 0.0; |
||
35 | |||
36 | /** @var float */ |
||
37 | protected $vat = 0.0; |
||
38 | |||
39 | /** @var float */ |
||
40 | protected $priceVat = 0.0; |
||
41 | |||
42 | |||
43 | /** |
||
44 | * @param IPriceCalculator |
||
45 | * @param float |
||
46 | * @param float |
||
47 | * @param float |
||
48 | * @param float |
||
49 | * @param float |
||
50 | * @param float |
||
51 | */ |
||
52 | public function __construct(IPriceCalculator $calculator, $basePrice, IDiscount $discount = NULL, |
||
53 | $price, $vatRate, $vat, $priceVat) |
||
54 | { |
||
55 | $this->calculator = $calculator; |
||
56 | $this->basePrice = $basePrice; |
||
57 | $this->discount = $discount; |
||
0 ignored issues
–
show
|
|||
58 | $this->price = $price; |
||
59 | $this->vatRate = $vatRate; |
||
60 | $this->vat = $vat; |
||
61 | $this->priceVat = $priceVat; |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * Return PriceCalculator instance. |
||
66 | * |
||
67 | * @return IPriceCalculator |
||
68 | */ |
||
69 | public function getCalculator() |
||
70 | { |
||
71 | return $this->calculator; |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * Get price without VAT and discount. |
||
76 | * |
||
77 | * @return float |
||
78 | */ |
||
79 | public function getBasePrice() |
||
80 | { |
||
81 | return $this->basePrice; |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * Get discount in percent without VAT. |
||
86 | * |
||
87 | * @return float |
||
88 | */ |
||
89 | public function getDiscount() |
||
90 | { |
||
91 | return $this->discount; |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * Get price after discount without VAT. |
||
96 | * |
||
97 | * @return float |
||
98 | */ |
||
99 | public function getPrice() |
||
100 | { |
||
101 | return $this->price; |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * Get VAT rate in percent. |
||
106 | * |
||
107 | * @return float |
||
108 | */ |
||
109 | public function getVatRate() |
||
110 | { |
||
111 | return $this->vatRate; |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * Get VAT value. |
||
116 | * |
||
117 | * @return float |
||
118 | */ |
||
119 | public function getVat() |
||
120 | { |
||
121 | return $this->vat; |
||
122 | } |
||
123 | |||
124 | /** |
||
125 | * Get price after discount with VAT. |
||
126 | * |
||
127 | * @return float |
||
128 | */ |
||
129 | public function getPriceVat() |
||
130 | { |
||
131 | return $this->priceVat; |
||
132 | } |
||
133 | |||
134 | /** |
||
135 | * Return all prices as array. |
||
136 | * |
||
137 | * @return array |
||
138 | */ |
||
139 | public function toArray() |
||
140 | { |
||
141 | return [ |
||
142 | 'basePrice' => $this->basePrice, |
||
143 | 'discount' => $this->discount ? $this->discount->value : 0.0, |
||
144 | 'price' => $this->price, |
||
145 | 'vatRate' => $this->vatRate, |
||
146 | 'vat' => $this->vat, |
||
147 | 'priceVat' => $this->priceVat, |
||
148 | ]; |
||
149 | } |
||
150 | |||
151 | } |
||
152 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.