1 | <?php |
||
12 | class ItemBasket implements \IteratorAggregate |
||
13 | { |
||
14 | /** |
||
15 | * @var ItemEnvelope[] Contained items |
||
16 | */ |
||
17 | private $items = []; |
||
18 | |||
19 | /** |
||
20 | * @var string Classname of currency used in basket |
||
21 | */ |
||
22 | private $currencyClassname = ''; |
||
23 | |||
24 | /** |
||
25 | * Optionally load items at construct |
||
26 | */ |
||
27 | 32 | public function __construct(ItemEnvelope ...$items) |
|
33 | |||
34 | /** |
||
35 | * Add item to basket |
||
36 | * |
||
37 | * @throws Exception If two items with different currencies are added |
||
38 | */ |
||
39 | 17 | public function addItem(ItemEnvelope $envelope): self |
|
52 | |||
53 | /** |
||
54 | * Get classname of currency used in basket |
||
55 | */ |
||
56 | 18 | public function getCurrencyClassname(): string |
|
60 | |||
61 | /** |
||
62 | * Create amount object using the current basket currency |
||
63 | * |
||
64 | * @throws Exception If no item is loaded and currency is unknown |
||
65 | */ |
||
66 | 12 | public function createCurrencyObject(string $value): Amount |
|
74 | |||
75 | /** |
||
76 | * Get contained items |
||
77 | * |
||
78 | * @return ItemEnvelope[] |
||
79 | */ |
||
80 | 15 | public function getItems(): array |
|
84 | |||
85 | /** |
||
86 | * Implements the IteratorAggregate interface |
||
87 | */ |
||
88 | 2 | public function getIterator(): \Traversable |
|
94 | |||
95 | /** |
||
96 | * Get number of items in basket |
||
97 | */ |
||
98 | 2 | public function getNrOfItems(): int |
|
102 | |||
103 | /** |
||
104 | * Get number of units in basket (each item may contain multiple units) |
||
105 | */ |
||
106 | 2 | public function getNrOfUnits(): int |
|
116 | |||
117 | /** |
||
118 | * Get total cost of all items (VAT excluded) |
||
119 | */ |
||
120 | 7 | public function getTotalUnitCost(): Amount |
|
124 | |||
125 | /** |
||
126 | * Get total VAT cost for all items |
||
127 | */ |
||
128 | 7 | public function getTotalVatCost(): Amount |
|
132 | |||
133 | /** |
||
134 | * Get total cost of all items (VAT included) |
||
135 | */ |
||
136 | 5 | public function getTotalCost(): Amount |
|
140 | |||
141 | /** |
||
142 | * Get charged vat amounts for non-zero vat rates |
||
143 | * |
||
144 | * @return Amount[] |
||
145 | */ |
||
146 | 2 | public function getVatRates(): array |
|
166 | |||
167 | /** |
||
168 | * Reduce loaded items to single amount using envelope method |
||
169 | */ |
||
170 | 9 | private function reduce(string $method): Amount |
|
180 | } |
||
181 |