Completed
Push — master ( 29ee36...16ede1 )
by Tom
03:58
created

MakeHelperCommand   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 61.36 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
lcom 2
cbo 3
dl 27
loc 44
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
B catchedExecute() 27 27 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
namespace N98\Magento\Command\Developer\Console;
4
5
use Magento\Framework\Code\Generator\ClassGenerator;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use Zend\Code\Generator\FileGenerator;
10
11
class MakeHelperCommand extends AbstractGeneratorCommand
12
{
13
    protected function configure()
14
    {
15
        $this
16
            ->setName('make:helper')
17
            ->addArgument('classpath', InputArgument::REQUIRED)
18
            ->setDescription('Creates a helper class');
19
    }
20
21
    /**
22
     * @param InputInterface $input
23
     * @param OutputInterface $output
24
     *
25
     * @return int|void
26
     */
27 View Code Duplication
    protected function catchedExecute(InputInterface $input, OutputInterface $output)
0 ignored issues
show
Duplication introduced by
This method 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...
28
    {
29
        $classFileName = $this->getNormalizedPathByArgument($input->getArgument('classpath'));
30
        $classNameToGenerate = $this->getCurrentModuleNamespace()
31
            . '\\Helper\\'
32
            . $this->getNormalizedClassnameByArgument($input->getArgument('classpath'));
33
        $filePathToGenerate = 'Helper/' . $classFileName . '.php';
34
35
        $classGenerator = $this->create(ClassGenerator::class);
36
37
        /** @var $classGenerator ClassGenerator */
38
        $classGenerator->setExtendedClass('AbstractHelper');
39
        $classGenerator->addUse('Magento\Framework\App\Helper\AbstractHelper');
40
41
        $classGenerator->setName($classNameToGenerate);
42
43
        $fileGenerator = FileGenerator::fromArray(
44
            [
45
                'classes' => [$classGenerator],
46
            ]
47
        );
48
49
        $directoryWriter = $this->getCurrentModuleDirectoryWriter();
50
        $directoryWriter->writeFile($filePathToGenerate, $fileGenerator->generate());
51
52
        $output->writeln('<info>generated </info><comment>' . $filePathToGenerate . '</comment>');
53
    }
54
}
55