Completed
Push — develop ( 5d5326...be0e9e )
by Christian
02:27
created

Command/Developer/Console/MakeInterfaceCommand.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace N98\Magento\Command\Developer\Console;
4
5
use Magento\Framework\Code\Generator\InterfaceGenerator;
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
/**
12
 * Class MakeInterfaceCommand
13
 * @package N98\Magento\Command\Developer\Console
14
 */
15 View Code Duplication
class MakeInterfaceCommand extends AbstractGeneratorCommand
0 ignored issues
show
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...
16
{
17
    const CLASSPATH = 'classpath';
18
19
    protected function configure()
20
    {
21
        $this
22
            ->setName('make:interface')
23
            ->addArgument(self::CLASSPATH, InputArgument::REQUIRED)
24
            ->setDescription('Creates a generic interface');
25
    }
26
27
    /**
28
     * @param InputInterface $input
29
     * @param OutputInterface $output
30
     *
31
     * @return int|void
32
     * @throws \Magento\Framework\Exception\FileSystemException
33
     */
34
    protected function catchedExecute(InputInterface $input, OutputInterface $output)
35
    {
36
        $classFileName = $this->getNormalizedPathByArgument($input->getArgument(self::CLASSPATH));
37
38
        $classNameToGenerate = $this->getCurrentModuleNamespace()
39
            . '\\'
40
            . $this->getNormalizedClassnameByArgument($input->getArgument(self::CLASSPATH));
41
42
        $filePathToGenerate = $classFileName . '.php';
43
44
        /** @var $classGenerator InterfaceGenerator */
45
        $classGenerator = $this->create(InterfaceGenerator::class);
46
        $classGenerator->setName($classNameToGenerate);
47
48
        $fileGenerator = FileGenerator::fromArray([
49
            'classes' => [$classGenerator],
50
        ]);
51
52
        $directoryWriter = $this->getCurrentModuleDirectoryWriter();
53
        $directoryWriter->writeFile($filePathToGenerate, $fileGenerator->generate());
54
55
        $output->writeln('<info>generated </info><comment>' . $filePathToGenerate . '</comment>');
56
    }
57
}
58