Completed
Push — master ( fdf082...9ad6b1 )
by Kevin
08:56 queued 05:59
created

ApiSet   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 59
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 21 1
B execute() 0 31 2
1
<?php
2
3
namespace Magium\Cli\Command;
4
5
use Magium\InvalidConfigurationException;
6
use Magium\NotFoundException;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\ArrayInput;
9
use Symfony\Component\Console\Input\InputArgument;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Input\InputOption;
12
use Symfony\Component\Console\Output\OutputInterface;
13
14
class ApiSet extends Command
15
{
16
17
    protected function configure()
18
    {
19
        $this->setName('api:set');
20
        $this->setDescription('Sets the API key, secret and (optionally) the hostname for the API');
21
        $this->addArgument(
22
            'key',
23
            InputArgument::REQUIRED,
24
            'The API key'
25
        );
26
        $this->addArgument(
27
            'secret',
28
            InputArgument::REQUIRED,
29
            'The key secret'
30
        );
31
        $this->addArgument(
32
            'hostname',
33
            InputArgument::OPTIONAL,
34
            'Changes the hostname'
35
        );
36
37
    }
38
39
    protected function execute(InputInterface $input, OutputInterface $output)
40
    {
41
        $command = $this->getApplication()->find('element:set');
42
        $input2 = new ArrayInput([
43
            'command'   => $command->getName(),
44
            'class'     => 'Magium\Util\Api\ApiConfiguration',
45
            'property'  => 'key',
46
            'value'     => $input->getArgument('key'),
47
        ]);
48
        $command->run($input2, $output);
49
50
        $input2 = new ArrayInput([
51
            'command'   => $command->getName(),
52
            'class'     => 'Magium\Util\Api\ApiConfiguration',
53
            'property'  => 'secret',
54
            'value'     => $input->getArgument('secret'),
55
        ]);
56
        $command->run($input2, $output);
57
58
        if ($input->getArgument('hostname')) {
59
60
            $input2 = new ArrayInput([
61
                'command'   => $command->getName(),
62
                'class'     => 'Magium\Util\Api\ApiConfiguration',
63
                'property'  => 'apiHostname',
64
                'value'     => $input->getArgument('hostname'),
65
            ]);
66
            $command->run($input2, $output);
67
        }
68
69
    }
70
71
    
72
}