SelectMagentoVersion   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 60
Duplicated Lines 11.67 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 11
c 2
b 1
f 0
lcom 1
cbo 2
dl 7
loc 60
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C execute() 7 52 11

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
namespace N98\Magento\Command\Installer\SubCommand;
4
5
use N98\Magento\Command\SubCommand\AbstractSubCommand;
6
7
class SelectMagentoVersion extends AbstractSubCommand
8
{
9
    /**
10
     * Check PHP environment against minimal required settings modules
11
     *
12
     * @return void
13
     */
14
    public function execute()
15
    {
16
        if ($this->input->getOption('noDownload')) {
17
            return;
18
        }
19
20
        if (
21
            $this->input->getOption('magentoVersion') == null
22
            && $this->input->getOption('magentoVersionByName') == null
23
        ) {
24
            $question = array();
25
            foreach ($this->commandConfig['magento-packages'] as $key => $package) {
26
                $question[] = '<comment>' . str_pad('[' . ($key + 1) . ']', 4, ' ') . '</comment> ' .
27
                    $package['name'] . "\n";
28
            }
29
            $question[] = "<question>Choose a magento version:</question> ";
30
31
            $commandConfig = $this->commandConfig;
32
33
34
            $type = $this->getCommand()->getHelper('dialog')->askAndValidate(
35
                $this->output,
36
                $question,
37 View Code Duplication
                function ($typeInput) use ($commandConfig) {
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...
38
                    if (!in_array($typeInput, range(1, count($this->commandConfig['magento-packages'])))) {
39
                        throw new \InvalidArgumentException('Invalid type');
40
                    }
41
42
                    return $typeInput;
43
                }
44
            );
45
        } else {
46
            $type = null;
47
48
            if ($this->input->getOption('magentoVersion')) {
49
                $type = $this->input->getOption('magentoVersion');
50
            } elseif ($this->input->getOption('magentoVersionByName')) {
51
                foreach ($this->commandConfig['magento-packages'] as $key => $package) {
52
                    if ($package['name'] == $this->input->getOption('magentoVersionByName')) {
53
                        $type = $key + 1;
54
                        break;
55
                    }
56
                }
57
            }
58
59
            if ($type == null) {
60
                throw new \InvalidArgumentException('Unable to locate Magento version');
61
            }
62
        }
63
64
        $this->config['magentoVersionData'] = $this->commandConfig['magento-packages'][$type - 1];
65
    }
66
}
67