RemoveProductFromCartCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 7
dl 0
loc 61
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A configure() 0 7 1
A execute() 0 22 1
1
<?php
2
3
namespace SyliusCart\CartBundle\Command;
4
5
use Broadway\CommandHandling\CommandBusInterface;
6
use Broadway\UuidGenerator\UuidGeneratorInterface;
7
use SyliusCart\Domain\Command\RemoveProductFromCart;
8
use Symfony\Component\Console\Command\Command;
9
use Symfony\Component\Console\Helper\QuestionHelper;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
use Symfony\Component\Console\Question\Question;
13
14
/**
15
 * @author Arkadiusz Krakowiak <[email protected]>
16
 */
17
final class RemoveProductFromCartCommand extends Command
18
{
19
    /**
20
     * @var CommandBusInterface
21
     */
22
    private $commandBus;
23
24
    /**
25
     * @var UuidGeneratorInterface
26
     */
27
    private $uuidGenerator;
28
29
    /**
30
     * @param CommandBusInterface $commandBus
31
     * @param UuidGeneratorInterface $uuidGenerator
32
     */
33
    public function __construct(CommandBusInterface $commandBus, UuidGeneratorInterface $uuidGenerator)
34
    {
35
        $this->commandBus = $commandBus;
36
        $this->uuidGenerator = $uuidGenerator;
37
38
        parent::__construct();
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    protected function configure()
45
    {
46
        $this
47
            ->setName('sylius:cart:remove-product-from-cart')
48
            ->setDescription('Remove product from cart')
49
        ;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    protected function execute(InputInterface $input, OutputInterface $output)
56
    {
57
        /** @var QuestionHelper $helper */
58
        $helper = $this->getHelper('question');
59
60
        $cartId = $helper->ask(
61
            $input,
62
            $output,
63
            new Question(
64
                sprintf('Cart id (%s): ', $this->uuidGenerator->generate()),
65
                $this->uuidGenerator->generate()
66
            )
67
        );
68
69
        $productCode = $helper->ask($input, $output, new Question('Product code: '));
70
71
        $cartItemRemove = RemoveProductFromCart::create($cartId, $productCode);
72
73
        $this->commandBus->dispatch($cartItemRemove);
74
75
        $output->writeln(sprintf('Item removed!'));
76
    }
77
}
78