ModuleMakeCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 15.38%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 46
ccs 2
cts 13
cp 0.1538
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 8 1
A handleExistingModule() 0 5 2
A getArguments() 0 4 1
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 26
    protected function getArguments()
53
    {
54
        return [
55 26
            ['name', InputArgument::REQUIRED, 'The name of the module that will be created.'],
56
        ];
57
    }
58
}
59