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

MakeClassCommand::execute()   B

Complexity

Conditions 2
Paths 9

Size

Total Lines 27
Code Lines 16

Duplication

Lines 27
Ratio 100 %

Importance

Changes 0
Metric Value
dl 27
loc 27
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 16
nc 9
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 MakeClassCommand extends AbstractGeneratorCommand
12
{
13
    const CLASSPATH = 'classpath';
14
15
    protected function configure()
16
    {
17
        $this
18
            ->setName('make:class')
19
            ->addArgument(self::CLASSPATH, InputArgument::REQUIRED)
20
            ->setDescription('Creates a generic class');
21
    }
22
23
    /**
24
     * @param InputInterface $input
25
     * @param OutputInterface $output
26
     *
27
     * @return int|void
28
     */
29
    protected function catchedExecute(InputInterface $input, OutputInterface $output)
30
    {
31
        $classFileName = $this->getNormalizedPathByArgument($input->getArgument(self::CLASSPATH));
32
33
        $classNameToGenerate = $this->getCurrentModuleNamespace()
34
            . '\\'
35
            . $this->getNormalizedClassnameByArgument($input->getArgument(self::CLASSPATH));
36
37
        $filePathToGenerate = $classFileName . '.php';
38
39
        /** @var $classGenerator ClassGenerator */
40
        $classGenerator = $this->create(ClassGenerator::class);
41
        $classGenerator->setName($classNameToGenerate);
42
43
        $fileGenerator = FileGenerator::fromArray([
44
            'classes' => [$classGenerator],
45
        ]);
46
47
        $directoryWriter = $this->getCurrentModuleDirectoryWriter();
48
        $directoryWriter->writeFile($filePathToGenerate, $fileGenerator->generate());
49
50
        $output->writeln('<info>generated </info><comment>' . $filePathToGenerate . '</comment>');
51
    }
52
}
53