Passed
Push — feature/create-console-bootstr... ( abaeda )
by Chema
04:15
created

MakeModuleCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 38
rs 10
c 0
b 0
f 0
ccs 0
cts 18
cp 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 21 2
A configure() 0 6 1
A getExpectedFilenames() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Console\Infrastructure\Command;
6
7
use Gacela\Console\ConsoleFacade;
8
use Gacela\Console\Domain\FilenameSanitizer\FilenameSanitizer;
9
use Gacela\Framework\DocBlockResolverAwareTrait;
10
use Symfony\Component\Console\Command\Command;
11
use Symfony\Component\Console\Input\InputArgument;
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Input\InputOption;
14
use Symfony\Component\Console\Output\OutputInterface;
15
16
/**
17
 * @method ConsoleFacade getFacade()
18
 */
19
final class MakeModuleCommand extends Command
20
{
21
    use DocBlockResolverAwareTrait;
22
23
    protected function configure(): void
24
    {
25
        $this->setName('make:module')
26
            ->setDescription('Generate a basic module with an empty ' . $this->getExpectedFilenames())
27
            ->addArgument('path', InputArgument::REQUIRED, 'The file path. For example "App/TestModule/TestSubModule"')
28
            ->addOption('short-name', 's', InputOption::VALUE_NONE, 'Remove module prefix to the class name');
29
    }
30
31
    protected function execute(InputInterface $input, OutputInterface $output): int
32
    {
33
        /** @var string $path */
34
        $path = $input->getArgument('path');
35
        $commandArguments = $this->getFacade()->parseArguments($path);
36
        $shortName = (bool)$input->getOption('short-name');
37
38
        foreach (FilenameSanitizer::EXPECTED_FILENAMES as $filename) {
39
            $fullPath = $this->getFacade()->generateFileContent(
40
                $commandArguments,
41
                $filename,
42
                $shortName
43
            );
44
            $output->writeln("> Path '{$fullPath}' created successfully");
45
        }
46
47
        $pieces = explode('/', $commandArguments->directory());
48
        $moduleName = end($pieces);
49
        $output->writeln("Module '{$moduleName}' created successfully");
50
51
        return self::SUCCESS;
52
    }
53
54
    private function getExpectedFilenames(): string
55
    {
56
        return implode(', ', FilenameSanitizer::EXPECTED_FILENAMES);
57
    }
58
}
59