Passed
Pull Request — master (#3)
by Danny
03:23
created

DownloadManagementToolCommand   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
c 1
b 0
f 1
lcom 1
cbo 3
dl 0
loc 38
ccs 24
cts 24
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 9 1
A execute() 0 19 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('filename', InputArgument::OPTIONAL, 'Filename, for path see: rabbit_mq_manager.path', 'rabbitmqadmin')
20 1
            ->addOption('hostname', null, InputOption::VALUE_REQUIRED, 'Hostname', 'localhost')
21 1
            ->addOption('port', null, InputOption::VALUE_REQUIRED, 'Port', 15672)
22 1
            ->setName('rabbitmq-manager:download:management-tool')
23 1
            ->setDescription('Download rabbitmqadmin management tool');
24 1
    }
25
26
    /**
27
     * @inheritdoc
28
     */
29 1
    protected function execute(InputInterface $input, OutputInterface $output)
30
    {
31 1
        $client = $this->getContainer()->get('myonlinestore_rabbitmq_manager.http_client');
32 1
        $filesystem = $this->getContainer()->get('myonlinestore_rabbitmq_manager.filesystem');
33
34 1
        $request = $client->createRequest(
35 1
            'GET',
36 1
            sprintf(
37 1
                'http://%s:%s/cli/rabbitmqadmin',
38 1
                $input->getOption('hostname'),
39 1
                $input->getOption('port')
40 1
            )
41 1
        );
42
43 1
        $filesystem->put(
44 1
            $input->getArgument('filename'),
45 1
            $client->send($request)->getBody()->getContents()
46 1
        );
47 1
    }
48
}
49