CreateModuleFolders   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 64
Duplicated Lines 18.75 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 8
c 2
b 1
f 0
lcom 1
cbo 2
dl 12
loc 64
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B execute() 12 58 8

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\Developer\Module\Create\SubCommand;
4
5
use N98\Magento\Command\SubCommand\AbstractSubCommand;
6
7
class CreateModuleFolders extends AbstractSubCommand
8
{
9
    /**
10
     * @return bool
11
     */
12
    public function execute()
13
    {
14
        $config = $this->config;
15
16
        if ($config->getBool('isModmanMode')) {
17
            $modManDir = sprintf('%s_%s/src', $config->getString('vendorNamespace'), $config->getString('moduleName'));
18
            if (file_exists($modManDir)) {
19
                throw new \RuntimeException('Module already exists. Stop.');
20
            }
21
            mkdir($modManDir, 0777, true);
22
            $config->setString('magentoRootFolder', './' . $modManDir);
0 ignored issues
show
Documentation introduced by
'./' . $modManDir is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
23
            $config->setString('modmanRootFolder', './' . substr($modManDir, 0, -4));
0 ignored issues
show
Documentation introduced by
'./' . substr($modManDir, 0, -4) is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
24
        }
25
26
        $moduleDir = $config->getString('magentoRootFolder')
27
            . '/app/code'
28
            . '/' . $config->getString('vendorNamespace')
29
            . '/' . $config->getString('moduleName');
30
        if (file_exists($moduleDir)) {
31
            throw new \RuntimeException('Module already exists. Stop.');
32
        }
33
34
        $config->setString('moduleDirectory', $moduleDir);
0 ignored issues
show
Documentation introduced by
$moduleDir is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
35
36
        mkdir($moduleDir, 0777, true);
37
        $this->output->writeln('<info>Created directory: <comment>' . $moduleDir . '<comment></info>');
38
39
        // Add etc folder
40
        mkdir($moduleDir . '/etc');
41
        $this->output->writeln('<info>Created directory: <comment>' . $moduleDir . '/etc<comment></info>');
42
43
        // Add blocks folder
44 View Code Duplication
        if ($config->getBool('shouldAddBlocks')) {
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...
45
            mkdir($moduleDir . '/Block');
46
            $this->output->writeln('<info>Created directory: <comment>' . $moduleDir . '/Block' . '<comment></info>');
47
        }
48
49
        // Add helpers folder
50 View Code Duplication
        if ($config->getBool('shouldAddHelpers')) {
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...
51
            mkdir($moduleDir . '/Helper');
52
            $this->output->writeln('<info>Created directory: <comment>' . $moduleDir . '/Helper' . '<comment></info>');
53
        }
54
55
        // Add models folder
56 View Code Duplication
        if ($config->getBool('shouldAddModels')) {
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...
57
            mkdir($moduleDir . '/Model');
58
            $this->output->writeln('<info>Created directory: <comment>' . $moduleDir . '/Model' . '<comment></info>');
59
        }
60
61
        // Create SQL and Data folder
62
        if ($config->getBool('shouldAddSetup')) {
63
            $setupFolder = $moduleDir . '/Setup/';
64
            mkdir($setupFolder, 0777, true);
65
            $this->output->writeln('<info>Created directory: <comment>' . $setupFolder . '<comment></info>');
66
        }
67
68
        return true;
69
    }
70
}
71