CreateModuleFolders::execute()   B
last analyzed

Complexity

Conditions 8
Paths 35

Size

Total Lines 58
Code Lines 34

Duplication

Lines 12
Ratio 20.69 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 12
loc 58
rs 7.1977
cc 8
eloc 34
nc 35
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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