Completed
Push — 2.x-dev-kit ( 8d77e1 )
by
unknown
28:22 queued 25:50
created

ListQueuesCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 4
c 2
b 1
f 0
lcom 0
cbo 4
dl 0
loc 30
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 5 1
A execute() 0 15 3
1
<?php
2
3
/*
4
 * This file is part of the Sonata package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\NotificationBundle\Command;
13
14
use Sonata\NotificationBundle\Backend\QueueDispatcherInterface;
15
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Output\OutputInterface;
18
19
class ListQueuesCommand extends ContainerAwareCommand
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function configure()
25
    {
26
        $this->setName('sonata:notification:list-queues');
27
        $this->setDescription('List all queues available');
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function execute(InputInterface $input, OutputInterface $output)
34
    {
35
        $backend = $this->getContainer()->get('sonata.notification.backend');
36
37
        if (!$backend instanceof QueueDispatcherInterface) {
38
            $output->writeln('The backend class <info>'.get_class($backend).'</info> does not provide multiple queues.');
39
40
            return;
41
        }
42
43
        $output->writeln('<info>List of queues available</info>');
44
        foreach ($backend->getQueues() as $queue) {
45
            $output->writeln(sprintf('queue: <info>%s</info> - routing_key: <info>%s</info>', $queue['queue'], $queue['routing_key']));
46
        }
47
    }
48
}
49