Completed
Pull Request — 1.x (#56)
by Christian
04:42 queued 03:39
created

ModifyCloudCommandTrait::execute()   B

Complexity

Conditions 6
Paths 32

Size

Total Lines 37

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
dl 0
loc 37
ccs 0
cts 17
cp 0
rs 8.7057
c 0
b 0
f 0
cc 6
nc 32
nop 2
crap 42
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\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
15
use Symfony\Component\Console\Command\Command;
16
use Symfony\Component\Console\Input\InputArgument;
17
use Symfony\Component\Console\Input\InputInterface;
18
use Symfony\Component\Console\Input\InputOption;
19
use Symfony\Component\Console\Output\OutputInterface;
20
21
if (class_exists(ContainerAwareCommand::class)) {
22
    /**
23
     * Modify a panda cloud via command-line.
24
     *
25
     * @author Christian Flothmann <[email protected]>
26
     *
27
     * @final since 1.5
28
     */
29
    class ModifyCloudCommand extends ContainerAwareCommand
30
    {
31
        use ModifyCloudCommandTrait;
32
33
        protected static $defaultName = 'panda:cloud:modify';
34
    }
35
} else {
36
    /**
37
     * Modify a panda cloud via command-line.
38
     *
39
     * @author Christian Flothmann <[email protected]>
40
     *
41
     * @final since 1.5
42
     */
43
    class ModifyCloudCommand extends Command
0 ignored issues
show
Comprehensibility Best Practice introduced by
The type Xabbuh\PandaBundle\Command\ModifyCloudCommand has been defined more than once; this definition is ignored, only the first definition in this file (L29-34) is considered.

This check looks for classes that have been defined more than once in the same file.

If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.

This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.

Loading history...
44
    {
45
        use ModifyCloudCommandTrait;
46
47
        protected static $defaultName = 'panda:cloud:modify';
48
    }
49
}
50
51
trait ModifyCloudCommandTrait
52
{
53
    /**
54
     * {@inheritDoc}
55
     */
56
    protected function configure()
57
    {
58
        $this->setName(static::$defaultName); // BC with Symfony Console 3.3 and older not handling the property automatically
0 ignored issues
show
Bug introduced by
It seems like setName() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
59
        $this->setDescription('Modify a cloud');
0 ignored issues
show
Bug introduced by
It seems like setDescription() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
60
        $this->addOption(
0 ignored issues
show
Bug introduced by
It seems like addOption() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
61
            'account',
62
            'a',
63
            InputOption::VALUE_REQUIRED,
64
            'The account to use to authenticate to the panda service'
65
        );
66
        $this->addOption('name', null, InputOption::VALUE_REQUIRED, 'The new cloud name');
0 ignored issues
show
Bug introduced by
It seems like addOption() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
67
        $this->addOption('s3-bucket', null, InputOption::VALUE_REQUIRED, 'The new AWS S3 bucket');
0 ignored issues
show
Bug introduced by
It seems like addOption() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
68
        $this->addOption('access-key', null, InputOption::VALUE_REQUIRED, 'The new access key');
0 ignored issues
show
Bug introduced by
It seems like addOption() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
69
        $this->addOption('secret-key', null, InputOption::VALUE_REQUIRED, 'The new secret key');
0 ignored issues
show
Bug introduced by
It seems like addOption() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
70
        $this->addArgument('cloud-id', InputArgument::REQUIRED, 'The id of the cloud being modified');
0 ignored issues
show
Bug introduced by
It seems like addArgument() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
71
    }
72
73
    /**
74
     * {@inheritDoc}
75
     */
76
    protected function execute(InputInterface $input, OutputInterface $output)
77
    {
78
        $data = array();
79
80
        // change the cloud name
81
        if ($name = $input->getOption('name')) {
82
            $data['name'] = $name;
83
        }
84
85
        // change the s3 bucket
86
        if ($s3bucket = $input->getOption('s3-bucket')) {
87
            $data['s3_videos_bucket'] = $s3bucket;
88
        }
89
90
        // change the access key
91
        if ($accessKey = $input->getOption('access-key')) {
92
            $data['aws_access_key'] = $accessKey;
93
        }
94
95
        // change the secret key
96
        if ($secretKey = $input->getOption('secret-key')) {
97
            $data['aws_secret_key'] = $secretKey;
98
        }
99
100
        // if anything has changed
101
        if (count($data) > 0) {
102
            // push these changes to the panda service
103
            $cloudFactory = $this->getContainer()->get('xabbuh_panda.cloud_factory');
0 ignored issues
show
Bug introduced by
It seems like getContainer() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
104
            $cloud = $cloudFactory->get(
105
                $input->getArgument('cloud-id'),
106
                $input->getOption('account')
107
            );
108
            $cloud->setCloud($data, $input->getArgument('cloud-id'));
109
        }
110
111
        return 0;
112
    }
113
}
114