Completed
Push — feature/merge-build-stop-step ( d59daf )
by Tom
8s
created

MakeInterfaceCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 8 8 1
B execute() 27 27 2

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\InterfaceGenerator;
6
use Magento\Framework\Module\Dir;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use Zend\Code\Generator\FileGenerator;
12
13 View Code Duplication
class MakeInterfaceCommand extends AbstractGeneratorCommand
0 ignored issues
show
Duplication introduced by
This class 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...
14
{
15
    const CLASSPATH = 'classpath';
16
17
    protected function configure()
18
    {
19
        $this
20
            ->setName('make:interface')
21
            ->addArgument(self::CLASSPATH, InputArgument::REQUIRED)
22
            ->setDescription('Creates a generic interface')
23
        ;
24
    }
25
26
    /**
27
     * @param InputInterface  $input
28
     * @param OutputInterface $output
29
     *
30
     * @return int|void
31
     */
32
    protected function execute(InputInterface $input, OutputInterface $output)
33
    {
34
        try {
35
            $classFileName = $this->getNormalizedPathByArgument($input->getArgument(self::CLASSPATH));
36
37
            $classNameToGenerate = $this->getCurrentModuleNamespace()
38
                . '\\'
39
                . $this->getNormalizedClassnameByArgument($input->getArgument(self::CLASSPATH));
40
41
            $filePathToGenerate = $classFileName . '.php';
42
43
            /** @var $classGenerator InterfaceGenerator */
44
            $classGenerator = $this->create(InterfaceGenerator::class);
45
            $classGenerator->setName($classNameToGenerate);
46
47
            $fileGenerator = FileGenerator::fromArray([
48
                'classes' => [$classGenerator]
49
            ]);
50
51
            $directoryWriter = $this->getCurrentModuleDirectoryWriter();
52
            $directoryWriter->writeFile($filePathToGenerate, $fileGenerator->generate());
53
54
            $output->writeln('<info>generated </info><comment>' . $filePathToGenerate . '</comment>');
55
        } catch (Exception $e) {
0 ignored issues
show
Bug introduced by
The class N98\Magento\Command\Developer\Console\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
56
            $output->writeln('<error>' . $e->getMessage() . '</error>');
57
        }
58
    }
59
60
}
61