RunCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 85
Duplicated Lines 47.06 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 10
Bugs 0 Features 5
Metric Value
wmc 4
c 10
b 0
f 5
lcom 1
cbo 5
dl 40
loc 85
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B configure() 29 29 1
B execute() 11 25 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Runs a command on a Cloud Foundry instance
4
 */
5
6
namespace Graviton\Deployment\Command\CloudFoundry;
7
8
use Graviton\Deployment\Command\AbstractCommand;
9
use Graviton\Deployment\Configuration;
10
use Graviton\Deployment\Deployment;
11
use Graviton\Deployment\Services\CloudFoundry\DeploymentUtils;
12
use Symfony\Component\Console\Input\InputArgument;
13
use Symfony\Component\Console\Input\InputInterface;
14
use Symfony\Component\Console\Input\InputOption;
15
use Symfony\Component\Console\Output\OutputInterface;
16
17
/**
18
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
19
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
20
 * @link     http://swisscom.ch
21
 */
22
final class RunCommand extends AbstractCommand
23
{
24
    /** @var Deployment */
25
    private $deployHandler;
26
27
    /**
28
     * @param Deployment    $deploymentHandler Managing the actual deployment
29
     * @param Configuration $configuration     Set of configuration options to influence the current command.
30
     * @param string|null   $name              Name of the command
31
     */
32
    public function __construct(Deployment $deploymentHandler, Configuration $configuration, $name = null)
33
    {
34
        parent::__construct($configuration, $name);
35
        $this->deployHandler = $deploymentHandler;
36
    }
37
38
    /**
39
     * Configures the current command.
40
     *
41
     * @return void
42
     */
43 View Code Duplication
    protected function configure()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
    {
45
        $this
46
            ->setName('graviton:deployment:cf:run')
47
            ->setDescription('Run a command as on a Cloud Foundry instance')
48
            ->addArgument(
49
                'applicationName',
50
                InputArgument::REQUIRED,
51
                'Which application shall be deployed?'
52
            )
53
            ->addArgument(
54
                'cmd',
55
                InputArgument::REQUIRED,
56
                'Shell command passed as a string e.g. "php app/console doctrine:mongodb:fixtures:load unstable"'
57
            )
58
            ->addArgument(
59
                'versionName',
60
                InputArgument::OPTIONAL,
61
                'Which application shall be deployed?',
62
                'unstable'
63
            )
64
            ->addOption(
65
                'no-logout',
66
                null,
67
                InputOption::VALUE_NONE,
68
                'Will keep the CF session open after deployment. ' .
69
                '<fg=yellow;options=bold>Keep in mind to close it by yourself!</fg=yellow;options=bold>'
70
            );
71
    }
72
73
    /**
74
     * Executes the current command.
75
     *
76
     * @param InputInterface  $input  User input on console
77
     * @param OutputInterface $output Output of the command
78
     *
79
     * @return void
80
     */
81
    protected function execute(InputInterface $input, OutputInterface $output)
82
    {
83
        DeploymentUtils::login($this->deployHandler, $output, $this->configuration);
84
        $applicationName = $input->getArgument('applicationName') . '-' . $input->getArgument('versionName');
85
        DeploymentUtils::runCommand(
86
            $this->deployHandler,
87
            $output,
88
            $this->configuration,
89
            $input->getArgument('cmd'),
90
            $applicationName
91
        );
92
        $noLogout = $input->getOption('no-logout');
93 View Code Duplication
        if (true == $noLogout) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
94
            $output->writeln(
95
                '<bg=yellow;fg=black;options=bold>' .
96
                '                                                                           ' . PHP_EOL .
97
                '  Cloud Foundry session will not be closed (»no-logout« option was set) !  ' .
98
                PHP_EOL . '                                                                           ' .
99
                '</bg=yellow;fg=black;options=bold>'
100
            );
101
102
            return;
103
        }
104
        DeploymentUtils::logout($this->deployHandler, $output, $this->configuration);
105
    }
106
}
107