Passed
Pull Request — master (#3)
by Danny
04:55
created

DownloadManagementToolCommand   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 2
c 2
b 0
f 2
lcom 1
cbo 4
dl 0
loc 51
ccs 35
cts 35
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 14 1
B execute() 0 27 1
1
<?php
2
3
namespace MyOnlineStore\Bundle\RabbitMqManagerBundle\Command;
4
5
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
final class DownloadManagementToolCommand extends ContainerAwareCommand
12
{
13
    /**
14
     * @inheritdoc
15
     */
16 1
    protected function configure()
17
    {
18 1
        $this
19 1
            ->addArgument(
20 1
                'filename',
21 1
                InputArgument::OPTIONAL,
22 1
                'Filename, for path see: rabbit_mq_manager.path',
23
                'rabbitmqadmin'
24 1
            )
25 1
            ->addOption('hostname', null, InputOption::VALUE_REQUIRED, 'Hostname', 'localhost')
26 1
            ->addOption('port', null, InputOption::VALUE_REQUIRED, 'Port', 15672)
27 1
            ->setName('rabbitmq-manager:download:management-tool')
28 1
            ->setDescription('Download rabbitmqadmin management tool');
29 1
    }
30
31
    /**
32
     * @inheritdoc
33
     */
34 1
    protected function execute(InputInterface $input, OutputInterface $output)
35
    {
36 1
        $client = $this->getContainer()->get('myonlinestore_rabbitmq_manager.http_client');
37 1
        $filesystem = $this->getContainer()->get('myonlinestore_rabbitmq_manager.filesystem');
38
39 1
        $request = $client->createRequest(
40 1
            'GET',
41 1
            sprintf(
42 1
                'http://%s:%s/cli/rabbitmqadmin',
43 1
                $input->getOption('hostname'),
44 1
                $input->getOption('port')
45 1
            )
46 1
        );
47
48 1
        $filesystem->put(
49 1
            $input->getArgument('filename'),
50 1
            $client->send($request)->getBody()->getContents()
51 1
        );
52
53 1
        $output->writeln(
54 1
            sprintf(
55 1
                'Saved to <comment>%s/%s</comment>',
56 1
                realpath($this->getContainer()->getParameter('mos_rabbitmq_cli_consumer.path')),
57 1
                $input->getArgument('filename')
58 1
            )
59 1
        );
60 1
    }
61
}
62