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

MakeModelCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 8 8 1
B execute() 32 32 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\Module\Dir;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use Magento\Framework\Code\Generator\ClassGenerator;
11
use Zend\Code\Generator\FileGenerator;
12
13 View Code Duplication
class MakeModelCommand 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
    protected function configure()
16
    {
17
        $this
18
            ->setName('make:model')
19
            ->addArgument('classpath', InputArgument::REQUIRED)
20
            ->setDescription('Creates a model class')
21
        ;
22
    }
23
24
    /**
25
     * @param InputInterface  $input
26
     * @param OutputInterface $output
27
     *
28
     * @return int|void
29
     */
30
    protected function execute(InputInterface $input, OutputInterface $output)
31
    {
32
        try {
33
            $modelFileName = $this->getNormalizedPathByArgument($input->getArgument('classpath'));
34
            $classNameToGenerate = $this->getCurrentModuleNamespace()
35
                . '\\Model\\'
36
                . $this->getNormalizedClassnameByArgument($input->getArgument('classpath'));
37
            $filePathToGenerate = 'Model/' . $modelFileName . '.php';
38
39
            $classGenerator = $this->create(ClassGenerator::class);
40
41
            /** @var $classGenerator ClassGenerator */
42
            $classGenerator->setExtendedClass('AbstractModel');
43
            $classGenerator->addUse('Magento\Framework\Model\AbstractModel');
44
45
            $classGenerator->setName($classNameToGenerate);
46
47
            $modelFileGenerator = FileGenerator::fromArray(
48
                [
49
                    'classes' => [$classGenerator]
50
                ]
51
            );
52
53
            $directoryWriter = $this->getCurrentModuleDirectoryWriter();
54
            $directoryWriter->writeFile($filePathToGenerate, $modelFileGenerator->generate());
55
56
            $output->writeln('<info>generated </info><comment>' . $filePathToGenerate . '</comment>');
57
58
        } 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...
59
            $output->writeln('<error>' . $e->getMessage() . '</error>');
60
        }
61
    }
62
63
}
64