CancelTicket   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 6 1
A execute() 0 8 1
A configure() 0 7 1
1
<?php
2
3
namespace ConferenceTools\Tickets\Cli\Command;
4
5
use Carnage\Cqrs\MessageBus\MessageBusInterface;
6
use ConferenceTools\Tickets\Domain\Command\Ticket\CancelTicket as CancelTicketCommand;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
class CancelTicket extends Command
13
{
14
    /**
15
     * @var MessageBusInterface
16
     */
17
    private $commandBus;
18
19
    public static function build(MessageBusInterface $commandBus)
20
    {
21
        $instance = new static();
22
        $instance->commandBus = $commandBus;
23
24
        return $instance;
25
    }
26
27
    protected function configure()
28
    {
29
        $this->setName('tickets:cancel-ticket')
30
            ->setDescription('Cancels a ticket - does not handle refund.')
31
            ->setDefinition([
32
                new InputArgument('purchaseId', InputArgument::REQUIRED, 'Purchase id'),
33
                new InputArgument('ticketId', InputArgument::REQUIRED, 'Ticket id'),
34
        ]);
35
    }
36
37
    protected function execute(InputInterface $input, OutputInterface $output)
38
    {
39
        $purchaseId = $input->getArgument('purchaseId');
40
        $ticketId = $input->getArgument('ticketId');
41
42
        $this->commandBus->dispatch(new CancelTicketCommand($purchaseId, $ticketId));
43
44
        $output->writeln(sprintf('Tickets cancelled. PurchaseId: %s', $purchaseId));
45
    }
46
}
47