Completed
Push — develop ( eba14b...6e538a )
by Baptiste
02:17
created

PurgeCommand::configure()   A

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 2
    protected function configure()
23
    {
24
        $this
25 2
            ->setName('innmind:amqp:purge')
26 2
            ->setDescription('Will delete all messages for the given queue')
27 2
            ->addArgument('queue', InputArgument::REQUIRED);
28 2
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 2
    protected function execute(InputInterface $input, OutputInterface $output)
34
    {
35 2
        $queue = $input->getArgument('queue');
36
        try {
37
            $this
38 2
                ->getContainer()
39 2
                ->get('innmind.amqp.client')
40 2
                ->channel()
41 2
                ->queue()
42 2
                ->purge(new Purge($queue));
43 1
        } catch (UnexpectedFrame $e) {
44 1
            $output->writeln(sprintf(
45 1
                '<error>Purging <bg=green>%s</> failed</>',
46 1
                $queue
47
            ));
48
49 1
            return 1;
50
        }
51 1
    }
52
}
53