Completed
Push — feature/merge-build-stop-step ( d59daf )
by Tom
8s
created

MakeClassCommand::execute()   B

Complexity

Conditions 2
Paths 9

Size

Total Lines 27
Code Lines 16

Duplication

Lines 27
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 27
loc 27
rs 8.8571
cc 2
eloc 16
nc 9
nop 2
1
<?php
2
3
namespace N98\Magento\Command\Developer\Console;
4
5
use Magento\Framework\Module\Dir;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use Magento\Framework\Code\Generator\ClassGenerator;
11
use Zend\Code\Generator\FileGenerator;
12
13 View Code Duplication
class MakeClassCommand 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...
14
{
15
    const CLASSPATH = 'classpath';
16
17
    protected function configure()
18
    {
19
        $this
20
            ->setName('make:class')
21
            ->addArgument(self::CLASSPATH, InputArgument::REQUIRED)
22
            ->setDescription('Creates a generic class')
23
        ;
24
    }
25
26
    /**
27
     * @param InputInterface  $input
28
     * @param OutputInterface $output
29
     *
30
     * @return int|void
31
     */
32
    protected function execute(InputInterface $input, OutputInterface $output)
33
    {
34
        try {
35
            $classFileName = $this->getNormalizedPathByArgument($input->getArgument(self::CLASSPATH));
36
37
            $classNameToGenerate = $this->getCurrentModuleNamespace()
38
                . '\\'
39
                . $this->getNormalizedClassnameByArgument($input->getArgument(self::CLASSPATH));
40
41
            $filePathToGenerate = $classFileName . '.php';
42
43
            /** @var $classGenerator ClassGenerator */
44
            $classGenerator = $this->create(ClassGenerator::class);
45
            $classGenerator->setName($classNameToGenerate);
46
47
            $fileGenerator = FileGenerator::fromArray([
48
                'classes' => [$classGenerator]
49
            ]);
50
51
            $directoryWriter = $this->getCurrentModuleDirectoryWriter();
52
            $directoryWriter->writeFile($filePathToGenerate, $fileGenerator->generate());
53
54
            $output->writeln('<info>generated </info><comment>' . $filePathToGenerate . '</comment>');
55
        } 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...
56
            $output->writeln('<error>' . $e->getMessage() . '</error>');
57
        }
58
    }
59
60
}
61