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

DownloadManagementToolCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 14
ccs 12
cts 12
cp 1
rs 9.4285
cc 1
eloc 11
nc 1
nop 0
crap 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