handleAddProductToCart()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
c 0
b 0
f 0
rs 9.6666
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace SyliusCart\Domain\CommandHandler;
6
7
use Broadway\CommandHandling\CommandHandler;
8
use Broadway\Repository\RepositoryInterface;
9
use SyliusCart\Domain\Command\AddProductToCart;
10
use SyliusCart\Domain\Model\CartContract;
11
12
/**
13
 * @author Arkadiusz Krakowiak <[email protected]>
14
 */
15
final class AddProductToCartCommandHandler extends CommandHandler
16
{
17
    /**
18
     * @var RepositoryInterface
19
     */
20
    private $cartRepository;
21
22
    /**
23
     * @param RepositoryInterface $cartRepository
24
     */
25
    public function __construct(RepositoryInterface $cartRepository)
26
    {
27
        $this->cartRepository = $cartRepository;
28
    }
29
30
    /**
31
     * @param AddProductToCart $command
32
     */
33
    public function handleAddProductToCart(AddProductToCart $command): void
34
    {
35
        /** @var CartContract $cart */
36
        $cart = $this->cartRepository->load($command->getCartId());
37
38
        $cart->addProductToCart($command->getProductCode(), $command->getQuantity(), $command->getPrice(), $command->getProductCurrencyCode());
39
40
        $this->cartRepository->save($cart);
41
    }
42
}
43