Passed
Push — master ( 40ce26...965fb6 )
by Arthur
22:04
created

ModuleMakeCommand::getOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 0
cts 5
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Foundation\Generator\Commands;
4
5
use Foundation\Core\Larapi;
6
use Foundation\Generator\Generators\DefaultModuleGenerator;
7
use Illuminate\Console\Command;
8
use Symfony\Component\Console\Input\InputArgument;
9
10
class ModuleMakeCommand extends Command
11
{
12
    /**
13
     * The console command name.
14
     *
15
     * @var string
16
     */
17
    protected $name = 'larapi:make:module';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Create a new module.';
25
26
    /**
27
     * Execute the console command.
28
     */
29
    public function handle()
30
    {
31
        $moduleName = ucfirst(strtolower($this->argument('name')));
0 ignored issues
show
Bug introduced by
It seems like $this->argument('name') can also be of type string[]; however, parameter $str of strtolower() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

31
        $moduleName = ucfirst(strtolower(/** @scrutinizer ignore-type */ $this->argument('name')));
Loading history...
32
33
        $this->handleExistingModule($moduleName);
34
35
        $generator = new DefaultModuleGenerator($moduleName);
36
        $generator->generate();
37
    }
38
39
    protected function handleExistingModule($moduleName)
40
    {
41
        if (Larapi::getModule($moduleName)->exists()) {
42
            $this->error('Module already exists. Please delete it first.');
43
            exit();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
44
        }
45
    }
46
47
    /**
48
     * Get the console command arguments.
49
     *
50
     * @return array
51
     */
52
    protected function getArguments()
53
    {
54
        return [
55
            ['name', InputArgument::REQUIRED, 'The name of the module that will be created.'],
56
        ];
57
    }
58
}
59