Completed
Pull Request — master (#37)
by Christian
03:46
created

ModifyCloudCommand::execute()   B

Complexity

Conditions 6
Paths 32

Size

Total Lines 34

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 34
ccs 13
cts 13
cp 1
rs 8.7537
c 0
b 0
f 0
cc 6
nc 32
nop 2
crap 6
1
<?php
2
3
/*
4
 * This file is part of the XabbuhPandaBundle package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Xabbuh\PandaBundle\Command;
13
14
use Symfony\Component\Console\Command\Command;
15
use Symfony\Component\Console\Input\InputArgument;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Input\InputOption;
18
use Symfony\Component\Console\Output\OutputInterface;
19
use Xabbuh\PandaBundle\Cloud\CloudFactoryInterface;
20
21
/**
22
 * Modify a panda cloud via command-line.
23
 *
24
 * @author Christian Flothmann <[email protected]>
25
 */
26
class ModifyCloudCommand extends Command
27
{
28
    protected static $defaultName = 'panda:cloud:modify';
29
30
    private $cloudFactory;
31
32 5
    public function __construct(CloudFactoryInterface $cloudFactory)
33
    {
34 5
        parent::__construct();
35 5
36 5
        $this->cloudFactory = $cloudFactory;
37 5
    }
38 5
39 5
    /**
40 5
     * {@inheritDoc}
41
     */
42 5
    protected function configure()
43 5
    {
44 5
        $this->setName(static::$defaultName); // BC with Symfony Console 3.3 and older not handling the property automatically
45 5
        $this->setDescription('Modify a cloud');
46 5
        $this->addOption(
47 5
            'account',
48
            'a',
49
            InputOption::VALUE_REQUIRED,
50
            'The account to use to authenticate to the panda service'
51
        );
52 4
        $this->addOption('name', null, InputOption::VALUE_REQUIRED, 'The new cloud name');
53
        $this->addOption('s3-bucket', null, InputOption::VALUE_REQUIRED, 'The new AWS S3 bucket');
54 4
        $this->addOption('access-key', null, InputOption::VALUE_REQUIRED, 'The new access key');
55
        $this->addOption('secret-key', null, InputOption::VALUE_REQUIRED, 'The new secret key');
56
        $this->addArgument('cloud-id', InputArgument::REQUIRED, 'The id of the cloud being modified');
57 4
    }
58 1
59
    /**
60
     * {@inheritDoc}
61
     */
62 4
    protected function execute(InputInterface $input, OutputInterface $output)
63 1
    {
64
        $data = array();
65
66
        // change the cloud name
67 4
        if ($name = $input->getOption('name')) {
68 1
            $data['name'] = $name;
69
        }
70
71
        // change the s3 bucket
72 4
        if ($s3bucket = $input->getOption('s3-bucket')) {
73 1
            $data['s3_videos_bucket'] = $s3bucket;
74
        }
75
76
        // change the access key
77 4
        if ($accessKey = $input->getOption('access-key')) {
78
            $data['aws_access_key'] = $accessKey;
79 3
        }
80 3
81 3
        // change the secret key
82 3
        if ($secretKey = $input->getOption('secret-key')) {
83
            $data['aws_secret_key'] = $secretKey;
84 3
        }
85
86 4
        // if anything has changed
87
        if (count($data) > 0) {
88
            // push these changes to the panda service
89
            $cloud = $this->cloudFactory->get(
90
                $input->getArgument('cloud-id'),
0 ignored issues
show
Bug introduced by
It seems like $input->getArgument('cloud-id') targeting Symfony\Component\Consol...nterface::getArgument() can also be of type array<integer,string> or null; however, Xabbuh\PandaBundle\Cloud...FactoryInterface::get() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
91
                $input->getOption('account')
92
            );
93
            $cloud->setCloud($data, $input->getArgument('cloud-id'));
0 ignored issues
show
Bug introduced by
It seems like $input->getArgument('cloud-id') targeting Symfony\Component\Consol...nterface::getArgument() can also be of type array<integer,string>; however, Xabbuh\PandaClient\Api\Cloud::setCloud() does only seem to accept string|null, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
94
        }
95
    }
96
}
97