MakeCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 57
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fire() 0 15 2
A getArguments() 0 6 1
A getOptions() 0 7 1
1
<?php
2
3
namespace Consigliere\Components\Commands;
4
5
use Illuminate\Console\Command as ComponentCommand;
6
use Consigliere\Components\Generators\ComponentGenerator;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputOption;
9
10
class MakeCommand extends ComponentCommand
11
{
12
    /**
13
     * The console command name.
14
     *
15
     * @var string
16
     */
17
    protected $name = 'component:make';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Generate new component.';
25
26
    /**
27
     * Execute the console command.
28
     *
29
     * @return mixed
30
     */
31
    public function fire()
32
    {
33
        $names = $this->argument('name');
34
35
        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...
36
            with(new ComponentGenerator($name))
37
                ->setFilesystem($this->laravel['files'])
38
                ->setComponent($this->laravel['components'])
39
                ->setConfig($this->laravel['config'])
40
                ->setConsole($this)
41
                ->setForce($this->option('force'))
42
                ->setPlain($this->option('plain'))
43
                ->generate();
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::IS_ARRAY, 'The names of components will be created.'],
56
        ];
57
    }
58
59
    protected function getOptions()
60
    {
61
        return [
62
            ['plain', 'p', InputOption::VALUE_NONE, 'Generate a plain component (without some resources).'],
63
            ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when component already exist.'],
64
        ];
65
    }
66
}
67