LoadCommand   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 63
Duplicated Lines 17.46 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 6
dl 11
loc 63
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 10 1
D execute() 11 41 9

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
 * For the full copyright and license information, please view the LICENSE.md
4
 * file that was distributed with this source code.
5
 */
6
7
namespace Notamedia\ConsoleJedi\Module\Command;
8
9
use Notamedia\ConsoleJedi\Application\CanRestartTrait;
10
use Notamedia\ConsoleJedi\Module\Exception\ModuleInstallException;
11
use Notamedia\ConsoleJedi\Module\Module;
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Input\InputOption;
14
use Symfony\Component\Console\Output\OutputInterface;
15
16
/**
17
 * Command for module installation / register.
18
 *
19
 * @author Marat Shamshutdinov <[email protected]>
20
 */
21
class LoadCommand extends ModuleCommand
22
{
23
    use CanRestartTrait;
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    protected function configure()
29
    {
30
        parent::configure();
31
32
        $this->setName('module:load')
33
            ->setDescription('Load and install module from Marketplace')
34
            ->addOption('no-update', 'nu', InputOption::VALUE_NONE, 'Don\' update module')
35
            ->addOption('no-register', 'ni', InputOption::VALUE_NONE, 'Load only, don\' register module')
36
            ->addOption('beta', 'b', InputOption::VALUE_NONE, 'Allow the installation of beta releases');
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    protected function execute(InputInterface $input, OutputInterface $output)
43
    {
44
        $module = new Module($input->getArgument('module'));
45
46
        if (!$module->isThirdParty()) {
47
            $output->writeln('<info>Loading kernel modules is unsupported</info>');
48
        }
49
50
        if ($input->getOption('beta')) {
51
            $module->setBeta();
52
        }
53
54
        $module->load();
55
56
        if (!$input->getOption('no-update')) {
57
            $modulesUpdated = null;
58 View Code Duplication
            while ($module->update($modulesUpdated)) {
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...
59
                if (is_array($modulesUpdated)) {
60
                    foreach ($modulesUpdated as $moduleName => $moduleVersion) {
61
                        $output->writeln(sprintf('updated %s to <info>%s</info>', $moduleName, $moduleVersion));
62
                    }
63
                }
64
                return $this->restartScript($input, $output);
65
            }
66
        }
67
68
        if (!$input->getOption('no-register')) {
69
            try {
70
                $module->register();
71
            } catch (ModuleInstallException $e) {
72
                $output->writeln(sprintf('<comment>%s</comment>', $e->getMessage()),
73
                    OutputInterface::VERBOSITY_VERBOSE);
74
                $output->writeln(sprintf('Module loaded, but <error>not registered</error>. You need to do it yourself in admin panel.',
75
                    $module->getName()));
76
            }
77
        }
78
79
        $output->writeln(sprintf('installed <info>%s</info>', $module->getName()));
80
81
        return 0;
82
    }
83
}