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

PurgeCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 1
cbo 5
dl 0
loc 36
ccs 18
cts 18
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
A execute() 0 19 2
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