Passed
Push — master ( 80db42...d275a8 )
by Anton
03:59 queued 23s
created

InstallCommand   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 49
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 6
dl 49
loc 49
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 20 20 1
A execute() 17 17 1

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
 * @copyright Bluz PHP Team
4
 * @link https://github.com/bluzphp/bluzman
5
 */
6
7
namespace Bluzman\Command\Module;
8
9
use Bluzman\Command\AbstractCommand;
10
use Composer\Console\Application as ComposerApplication;
11
use Symfony\Component\Console\Input\ArrayInput;
12
use Symfony\Component\Console\Input\InputArgument;
13
use Symfony\Component\Console\Input\InputInterface;
14
use Symfony\Component\Console\Output\OutputInterface;
15
16
/**
17
 * Class List command
18
 *
19
 * @package Bluzman\Command
20
 *
21
 * @author   Pavel Machekhin
22
 * @created  2013-03-28 14:03
23
 */
24 View Code Duplication
class InstallCommand extends AbstractCommand
0 ignored issues
show
Duplication introduced by
This class 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...
25
{
26
    /**
27
     * Command configuration
28
     */
29 14
    protected function configure()
30
    {
31
        $this
32
            // the name of the command (the part after "bin/bluzman")
33 14
            ->setName('module:install')
34
            // the short description shown while running "php bin/bluzman list"
35 14
            ->setDescription('Install new module')
36
            // the full command description shown when running the command with
37
            // the "--help" option
38 14
            ->setHelp('Install module, for retrieve list run command <info>bluzman module:list</info>')
39
        ;
40
41 14
        $module = new InputArgument(
42 14
            'module',
43 14
            InputArgument::REQUIRED,
44 14
            'Module name is required'
45
        );
46
47 14
        $this->getDefinition()->addArgument($module);
48 14
    }
49
50
    /**
51
     * @param InputInterface $input
52
     * @param OutputInterface $output
53
     * @return int|null|void
54
     */
55
    protected function execute(InputInterface $input, OutputInterface $output)
56
    {
57
        // Composer\Factory::getHomeDir() method
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
58
        // needs COMPOSER_HOME environment variable set
59
        // putenv('COMPOSER_HOME=' . PATH_VENDOR . '/bin/composer');
0 ignored issues
show
Unused Code Comprehensibility introduced by
36% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
60
61
        $arguments = [
62
            'command' => 'require',
63
            'packages' => ['bluzphp/module-'. $input->getArgument('module')]
64
        ];
65
66
        // call `composer install` command programmatically
67
        $composerInput = new ArrayInput($arguments);
68
        $application = new ComposerApplication();
69
        $application->setAutoExit(false); // prevent `$application->run` method from exiting the script
70
        $application->run($composerInput);
71
    }
72
}
73