| Total Complexity | 5 |
| Total Lines | 30 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 13 | final class CartUseCase |
||
| 14 | { |
||
| 15 | public function __construct( |
||
| 16 | private CartRepository $repository, |
||
|
|
|||
| 17 | private Prices $prices |
||
| 18 | ) { |
||
| 19 | 2 | } |
|
| 20 | |||
| 21 | 2 | public function add(string $cartId, string $productId, int $amount): void |
|
| 22 | 2 | { |
|
| 23 | 2 | $cart = $this->get($cartId); |
|
| 24 | $cart->add($productId, $amount); |
||
| 25 | 1 | $this->repository->add($cart); |
|
| 26 | } |
||
| 27 | 1 | ||
| 28 | 1 | public function detail(string $cartId): CartDetail |
|
| 29 | 1 | { |
|
| 30 | 1 | return $this->get($cartId)->calculate($this->prices); |
|
| 31 | } |
||
| 32 | 1 | ||
| 33 | private function get(string $cartId): Cart |
||
| 34 | 1 | { |
|
| 35 | try { |
||
| 36 | return $this->repository->get($cartId); |
||
| 37 | 1 | } catch (CartNotFoundException $e) { |
|
| 38 | return new Cart($cartId); |
||
| 39 | } |
||
| 40 | 1 | } |
|
| 41 | } |
||
| 42 |