MakeInstanceCommand   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 7
c 3
b 0
f 2
lcom 1
cbo 2
dl 0
loc 78
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A fire() 0 10 3
A getStub() 0 8 2
A getDefaultNamespace() 0 4 1
A getOptions() 0 7 1
1
<?php
2
3
namespace R\Hive\Commands;
4
5
use Illuminate\Console\GeneratorCommand;
6
use Illuminate\Support\Str;
7
use Symfony\Component\Console\Input\InputOption;
8
9
class MakeInstanceCommand extends GeneratorCommand
10
{
11
    /**
12
     * The console command name.
13
     *
14
     * @var string
15
     */
16
    protected $name = 'hive:instance';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Create a new Hive instance class.';
24
25
    /**
26
     * The type of class being generated.
27
     *
28
     * @var string
29
     */
30
    protected $type = 'Instance';
31
32
    /**
33
     * Execute the console command.
34
     *
35
     * @return void
36
     */
37
    public function fire()
38
    {
39
        if (parent::fire() !== false) {
40
            if ($this->option('migration')) {
41
                $table = Str::plural(Str::snake(class_basename($this->argument('name'))));
0 ignored issues
show
Bug introduced by
It seems like $this->argument('name') targeting Illuminate\Console\Command::argument() can also be of type array; however, class_basename() does only seem to accept string|object, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
42
43
                $this->call('make:migration', ['name' => "create_{$table}_table", '--create' => $table]);
44
            }
45
        }
46
    }
47
48
    /**
49
     * Get the stub file for the generator.
50
     *
51
     * @return string
52
     */
53
    protected function getStub()
54
    {
55
        if ($this->option('eloquent')) {
56
            return __DIR__.'/stubs/instance-eloquent.stub';
57
        } else {
58
            return __DIR__.'/stubs/instance-no-eloquent.stub';
59
        }
60
    }
61
62
    /**
63
     * Get the default namespace for the class.
64
     *
65
     * @param string $rootNamespace
66
     *
67
     * @return string
68
     */
69
    protected function getDefaultNamespace($rootNamespace)
70
    {
71
        return $rootNamespace;
72
    }
73
74
    /**
75
     * Get the console command options.
76
     *
77
     * @return array
78
     */
79
    protected function getOptions()
80
    {
81
        return [
82
            ['eloquent', 'e', InputOption::VALUE_NONE, 'Extend the eloquent model class.'],
83
            ['migration', 'm', InputOption::VALUE_NONE, 'Create a new migration file for the model.'],
84
        ];
85
    }
86
}
87