Completed
Push — master ( 0c5b7b...2c9e38 )
by Tom
13:30
created

MakeHelperCommand::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 1
Metric Value
c 2
b 0
f 1
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 View Code Duplication
class MakeHelperCommand 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...
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
    protected function execute(InputInterface $input, OutputInterface $output)
28
    {
29
        try {
30
            $classFileName = $this->getNormalizedPathByArgument($input->getArgument('classpath'));
31
            $classNameToGenerate = $this->getCurrentModuleNamespace()
32
                . '\\Helper\\'
33
                . $this->getNormalizedClassnameByArgument($input->getArgument('classpath'));
34
            $filePathToGenerate = 'Helper/' . $classFileName . '.php';
35
36
            $classGenerator = $this->create(ClassGenerator::class);
37
38
            /** @var $classGenerator ClassGenerator */
39
            $classGenerator->setExtendedClass('AbstractHelper');
40
            $classGenerator->addUse('Magento\Framework\App\Helper\AbstractHelper');
41
42
            $classGenerator->setName($classNameToGenerate);
43
44
            $fileGenerator = FileGenerator::fromArray(
45
                [
46
                    'classes' => [$classGenerator],
47
                ]
48
            );
49
50
            $directoryWriter = $this->getCurrentModuleDirectoryWriter();
51
            $directoryWriter->writeFile($filePathToGenerate, $fileGenerator->generate());
52
53
            $output->writeln('<info>generated </info><comment>' . $filePathToGenerate . '</comment>');
54
        } 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...
55
            $output->writeln('<error>' . $e->getMessage() . '</error>');
56
        }
57
    }
58
}
59