Completed
Push — master ( 664783...554f9d )
by
unknown
15:59
created

ProduceCommand   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 68.18%

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 1
cbo 3
dl 0
loc 44
ccs 15
cts 22
cp 0.6818
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 19 1
A execute() 0 9 1
1
<?php
2
3
/**
4
 * Sends a given message to the message bus.
5
 */
6
7
namespace Graviton\RabbitMqBundle\Command;
8
9
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
use Symfony\Component\Console\Input\InputArgument;
13
14
/**
15
 * Sends a given message to the message bus.
16
 *
17
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
18
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
19
 * @link     http://swisscom.ch
20
 */
21
class ProduceCommand extends ContainerAwareCommand
22
{
23
24
    /**
25
     * Configures command
26
     *
27
     * @return void
28
     */
29 4
    protected function configure()
30
    {
31 4
        parent::configure();
32 4
        $this->setName('graviton:message:produce')
33 4
            ->setDescription(
34 4
                'Puts a message onto the RabbitMQ channel.'
35
            )
36 4
            ->addArgument(
37 4
                'message',
38 4
                InputArgument::REQUIRED,
39 4
                'The message to be sent e.g. "bundle.resource.update"'
40
            )
41 4
            ->addArgument(
42 4
                'data',
43 4
                InputArgument::OPTIONAL,
44 4
                'JSON formatted data to send to with the message.',
45 4
                '{}'
46
            );
47 4
    }
48
49
    /**
50
     * @param InputInterface  $input  The input
51
     * @param OutputInterface $output The output
52
     *
53
     * @return void
54
     */
55
    protected function execute(InputInterface $input, OutputInterface $output)
56
    {
57
        $producer = $this->getContainer()->get('graviton.message.jobproducer');
58
        $producer->setContentType('application/json');
59
        $producer->publish(
60
            $input->getArgument('data'),
61
            $input->getArgument('message')
62
        );
63
    }
64
}
65