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

MakeModelCommand::execute()   B

Complexity

Conditions 2
Paths 11

Size

Total Lines 31
Code Lines 18

Duplication

Lines 31
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 31
loc 31
rs 8.8571
cc 2
eloc 18
nc 11
nop 2
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 MakeModelCommand extends AbstractGeneratorCommand
12
{
13
    protected function configure()
14
    {
15
        $this
16
            ->setName('make:model')
17
            ->addArgument('classpath', InputArgument::REQUIRED)
18
            ->setDescription('Creates a model 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
        $modelFileName = $this->getNormalizedPathByArgument($input->getArgument('classpath'));
30
        $classNameToGenerate = $this->getCurrentModuleNamespace()
31
            . '\\Model\\'
32
            . $this->getNormalizedClassnameByArgument($input->getArgument('classpath'));
33
        $filePathToGenerate = 'Model/' . $modelFileName . '.php';
34
35
        $classGenerator = $this->create(ClassGenerator::class);
36
37
        /** @var $classGenerator ClassGenerator */
38
        $classGenerator->setExtendedClass('AbstractModel');
39
        $classGenerator->addUse('Magento\Framework\Model\AbstractModel');
40
41
        $classGenerator->setName($classNameToGenerate);
42
43
        $modelFileGenerator = FileGenerator::fromArray(
44
            [
45
                'classes' => [$classGenerator],
46
            ]
47
        );
48
49
        $directoryWriter = $this->getCurrentModuleDirectoryWriter();
50
        $directoryWriter->writeFile($filePathToGenerate, $modelFileGenerator->generate());
51
52
        $output->writeln('<info>generated </info><comment>' . $filePathToGenerate . '</comment>');
53
    }
54
}
55