| Total Complexity | 12 |
| Total Lines | 80 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 8 | class Cart |
||
| 9 | { |
||
| 10 | |||
| 11 | /** |
||
| 12 | * @var Product[] |
||
| 13 | */ |
||
| 14 | protected $items = []; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @return static |
||
| 18 | */ |
||
| 19 | public static function make(): self |
||
| 22 | } |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @param Product $product |
||
| 26 | * @return static |
||
| 27 | */ |
||
| 28 | public function addItem(Product $product): self |
||
| 29 | { |
||
| 30 | $this->items[] = $product; |
||
| 31 | return $this; |
||
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @return Product[] |
||
| 36 | */ |
||
| 37 | public function getItems(): array |
||
| 38 | { |
||
| 39 | return $this->items; |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @param Customer $customer |
||
| 44 | * @param bool|null $force |
||
| 45 | * @return bool |
||
| 46 | */ |
||
| 47 | public function canBuy(Customer $customer, bool $force = null): bool |
||
| 48 | { |
||
| 49 | foreach ($this->items as $item) { |
||
| 50 | if (!$item->canBuy($customer, $force)) { |
||
| 51 | return false; |
||
| 52 | } |
||
| 53 | } |
||
| 54 | |||
| 55 | return true; |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @return int |
||
| 60 | */ |
||
| 61 | public function getTotal(): int |
||
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @return array|null |
||
| 72 | */ |
||
| 73 | public function getMeta(): ?array |
||
| 88 | } |
||
| 89 | |||
| 90 | } |
||
| 91 |