Completed
Push — master ( 0fd405...f8ea68 )
by Nicolas
8s
created

ModuleMakeCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 55
ccs 16
cts 16
cp 1
rs 10
wmc 4
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 15 2
A getArguments() 0 6 1
A getOptions() 0 7 1
1
<?php
2
3
namespace Nwidart\Modules\Commands;
4
5
use Illuminate\Console\Command;
6
use Nwidart\Modules\Generators\ModuleGenerator;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputOption;
9
10
class ModuleMakeCommand extends Command
11
{
12
    /**
13
     * The console command name.
14
     *
15
     * @var string
16
     */
17
    protected $name = 'module:make';
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 91
    public function handle()
30
    {
31 91
        $names = $this->argument('name');
32
33 91
        foreach ($names as $name) {
0 ignored issues
show
Bug introduced by
The expression $names of type string|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
34 91
            with(new ModuleGenerator($name))
35 91
                ->setFilesystem($this->laravel['files'])
36 91
                ->setModule($this->laravel['modules'])
37 91
                ->setConfig($this->laravel['config'])
38 91
                ->setConsole($this)
39 91
                ->setForce($this->option('force'))
40 91
                ->setPlain($this->option('plain'))
41 91
                ->generate();
42
        }
43 91
    }
44
45
    /**
46
     * Get the console command arguments.
47
     *
48
     * @return array
49
     */
50 91
    protected function getArguments()
51
    {
52
        return [
53 91
            ['name', InputArgument::IS_ARRAY, 'The names of modules will be created.'],
54
        ];
55
    }
56
57 91
    protected function getOptions()
58
    {
59
        return [
60 91
            ['plain', 'p', InputOption::VALUE_NONE, 'Generate a plain module (without some resources).'],
61
            ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when module already exist.'],
62
        ];
63
    }
64
}
65