Completed
Push — master ( 624c9b...b71fe2 )
by Nicolas
04:08 queued 01:49
created

ModuleMakeCommand::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 11
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 15
ccs 12
cts 12
cp 1
crap 2
rs 9.4285
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 60
    public function handle()
30
    {
31 60
        $names = $this->argument('name');
32
33 60
        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 60
            with(new ModuleGenerator($name))
35 60
                ->setFilesystem($this->laravel['files'])
36 60
                ->setModule($this->laravel['modules'])
37 60
                ->setConfig($this->laravel['config'])
38 60
                ->setConsole($this)
39 60
                ->setForce($this->option('force'))
40 60
                ->setPlain($this->option('plain'))
41 60
                ->generate();
42
        }
43 60
    }
44
45
    /**
46
     * Get the console command arguments.
47
     *
48
     * @return array
49
     */
50 60
    protected function getArguments()
51
    {
52
        return [
53 60
            ['name', InputArgument::IS_ARRAY, 'The names of modules will be created.'],
54
        ];
55
    }
56
57 60
    protected function getOptions()
58
    {
59
        return [
60 60
            ['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