Completed
Push — develop ( f30ad5...49592b )
by Tom
03:52
created

MakeBlockCommand::catchedExecute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
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 MakeBlockCommand extends AbstractGeneratorCommand
12
{
13
    protected function configure()
14
    {
15
        $this
16
            ->setName('make:block')
17
            ->addArgument('classpath', InputArgument::REQUIRED)
18
            ->setDescription('Creates a generic block class');
19
    }
20
21
    /**
22
     * @param InputInterface $input
23
     * @param OutputInterface $output
24
     *
25
     * @return int|void
26
     */
27
    protected function catchedExecute(InputInterface $input, OutputInterface $output)
28
    {
29
        $this->createClassFile($input, $output);
30
    }
31
32
    /**
33
     * @param InputInterface $input
34
     * @param OutputInterface $output
35
     */
36 View Code Duplication
    private function createClassFile(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...
37
    {
38
        $blockFileName = $this->getNormalizedPathByArgument($input->getArgument('classpath'));
39
        $classNameToGenerate = $this->getCurrentModuleNamespace()
40
            . '\\Block\\'
41
            . $this->getNormalizedClassnameByArgument($input->getArgument('classpath'));
42
        $filePathToGenerate = 'Block/' . $blockFileName . '.php';
43
44
        $classGenerator = $this->create(ClassGenerator::class);
45
46
        /** @var $classGenerator ClassGenerator */
47
        $classGenerator->setExtendedClass('Template');
48
        $classGenerator->addUse('Magento\Framework\View\Element\Template');
49
50
        $classGenerator->setName($classNameToGenerate);
51
52
        $fileGenerator = FileGenerator::fromArray(
53
            [
54
                'classes' => [$classGenerator],
55
            ]
56
        );
57
58
        $directoryWriter = $this->getCurrentModuleDirectoryWriter();
59
        $directoryWriter->writeFile($filePathToGenerate, $fileGenerator->generate());
60
61
        $output->writeln('<info>generated </info><comment>' . $filePathToGenerate . '</comment>');
62
    }
63
}
64