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

MakeHelperCommand::catchedExecute()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 15

Duplication

Lines 27
Ratio 100 %

Importance

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