| Total Complexity | 11 |
| Total Lines | 71 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | class Cart implements \Bavix\Wallet\Interfaces\Cart, Group |
||
| 10 | { |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @var Product[] |
||
| 14 | */ |
||
| 15 | protected $items = []; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @inheritDoc |
||
| 19 | */ |
||
| 20 | public function addItem(Product $product): Group |
||
| 21 | { |
||
| 22 | $this->items[] = $product; |
||
| 23 | return $this; |
||
| 24 | } |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @inheritDoc |
||
| 28 | */ |
||
| 29 | public function getItems(): array |
||
| 30 | { |
||
| 31 | return $this->items; |
||
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @param Customer $customer |
||
| 36 | * @param bool|null $force |
||
| 37 | * @return bool |
||
| 38 | */ |
||
| 39 | public function canBuy(Customer $customer, bool $force = null): bool |
||
| 40 | { |
||
| 41 | foreach ($this->items as $item) { |
||
| 42 | if (!$item->canBuy($customer, $force)) { |
||
| 43 | return false; |
||
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | return true; |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @return int |
||
| 52 | */ |
||
| 53 | public function getAmountProduct(): int |
||
| 54 | { |
||
| 55 | $result = 0; |
||
| 56 | foreach ($this->items as $item) { |
||
| 57 | $result += $item->getAmountProduct(); |
||
| 58 | } |
||
| 59 | return $result; |
||
| 60 | } |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @return array|null |
||
| 64 | */ |
||
| 65 | public function getMetaProduct(): ?array |
||
| 80 | } |
||
| 81 | |||
| 82 | } |
||
| 83 |