Completed
Pull Request — 2.x (#54)
by Christian
13:17 queued 12:13
created

ModifyCloudCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
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\CloudFactory;
20
21
/**
22
 * Modify a panda cloud via command-line.
23
 *
24
 * @author Christian Flothmann <[email protected]>
25
 *
26
 * @final
27
 */
28
class ModifyCloudCommand extends Command
29
{
30
    protected static $defaultName = 'panda:cloud:modify';
31
32
    private $cloudFactory;
33
34
    public function __construct(CloudFactory $cloudFactory)
35
    {
36
        $this->cloudFactory = $cloudFactory;
37
    }
38
39
    /**
40
     * {@inheritDoc}
41
     */
42
    protected function configure()
43
    {
44
        $this->setName(static::$defaultName); // BC with Symfony Console 3.3 and older not handling the property automatically
45
        $this->setDescription('Modify a cloud');
46
        $this->addOption(
47
            'account',
48
            'a',
49
            InputOption::VALUE_REQUIRED,
50
            'The account to use to authenticate to the panda service'
51
        );
52
        $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
        $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
    }
58
59
    /**
60
     * {@inheritDoc}
61
     */
62
    protected function execute(InputInterface $input, OutputInterface $output)
63
    {
64
        $data = array();
65
66
        // change the cloud name
67
        if ($name = $input->getOption('name')) {
68
            $data['name'] = $name;
69
        }
70
71
        // change the s3 bucket
72
        if ($s3bucket = $input->getOption('s3-bucket')) {
73
            $data['s3_videos_bucket'] = $s3bucket;
74
        }
75
76
        // change the access key
77
        if ($accessKey = $input->getOption('access-key')) {
78
            $data['aws_access_key'] = $accessKey;
79
        }
80
81
        // change the secret key
82
        if ($secretKey = $input->getOption('secret-key')) {
83
            $data['aws_secret_key'] = $secretKey;
84
        }
85
86
        // 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\CloudFactory::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
        return 0;
97
    }
98
}
99