PurgeCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\AMQPBundle\Command;
5
6
use Innmind\AMQP\{
7
    Model\Queue\Purge,
8
    Exception\UnexpectedFrame
9
};
10
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
11
use Symfony\Component\Console\{
12
    Input\InputInterface,
13
    Input\InputArgument,
14
    Output\OutputInterface
15
};
16
17
final class PurgeCommand extends ContainerAwareCommand
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22 4
    protected function configure()
23
    {
24
        $this
25 4
            ->setName('innmind:amqp:purge')
26 4
            ->setDescription('Will delete all messages for the given queue')
27 4
            ->addArgument('queue', InputArgument::REQUIRED);
28 4
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 4
    protected function execute(InputInterface $input, OutputInterface $output)
34
    {
35 4
        $queue = $input->getArgument('queue');
36
        try {
37
            $this
38 4
                ->getContainer()
39 4
                ->get('innmind.amqp.client')
40 4
                ->channel()
41 4
                ->queue()
42 4
                ->purge(new Purge($queue));
43 2
        } catch (UnexpectedFrame $e) {
44 2
            $output->writeln(sprintf(
45 2
                '<error>Purging <bg=green>%s</> failed</>',
46 2
                $queue
47
            ));
48
49 2
            return 1;
50
        }
51 2
    }
52
}
53