ChangeProductQuantityCommandHandler::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
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\ChangeProductQuantity;
10
use SyliusCart\Domain\Model\CartContract;
11
12
/**
13
 * @author Arkadiusz Krakowiak <[email protected]>
14
 */
15 View Code Duplication
final class ChangeProductQuantityCommandHandler extends CommandHandler
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 ChangeProductQuantity $command
32
     */
33
    public function handleChangeProductQuantity(ChangeProductQuantity $command): void
34
    {
35
        /** @var CartContract $cart */
36
        $cart = $this->cartRepository->load($command->getCartId());
37
38
        $cart->changeProductQuantity($command->getProductCode(), $command->getNewQuantity());
39
40
        $this->cartRepository->save($cart);
41
    }
42
}
43