Completed
Push — develop ( 53c9e6...feab1b )
by Baptiste
07:33
created

ConsumeCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 39
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 8 1
A execute() 0 21 2
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\AMQPBundle\Command;
5
6
use Innmind\AMQP\Model\Basic\Consume;
7
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
8
use Symfony\Component\Console\{
9
    Input\InputInterface,
10
    Input\InputArgument,
11
    Output\OutputInterface
12
};
13
14
final class ConsumeCommand extends ContainerAwareCommand
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    protected function configure()
20
    {
21
        $this
22
            ->setName('innmind:amqp:consume')
23
            ->setDescription('Will process messages from the given queue')
24
            ->addArgument('queue', InputArgument::REQUIRED)
25
            ->addArgument('number', InputArgument::OPTIONAL, 'The number of messages to process');
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    protected function execute(InputInterface $input, OutputInterface $output)
32
    {
33
        $queue = $input->getArgument('queue');
34
        $consume = $this
35
            ->getContainer()
36
            ->get('innmind.amqp.consumers')
37
            ->get($queue);
38
39
        $consumer = $this
40
            ->getContainer()
41
            ->get('innmind.amqp.client')
42
            ->channel()
43
            ->basic()
44
            ->consume(new Consume($queue));
45
46
        if ($input->getArgument('number')) {
47
            $consumer->take((int) $input->getArgument('number'));
48
        }
49
50
        $consumer->foreach($consume);
51
    }
52
}
53