PivotTableCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 14 1
A parseTables() 0 8 1
A schema() 0 6 1
A keys() 0 6 1
1
<?php namespace Wn\Generators\Commands;
2
3
4
class PivotTableCommand extends BaseCommand {
5
6
	protected $signature = 'wn:pivot-table
7
        {model1 : Name of the first model or table}
8
        {model2 : Name of the second model or table}
9
        {--add= : specifies additional columns like timestamps, softDeletes, rememberToken and nullableTimestamps.}
10
        {--file= : name of the migration file (to use only for testing purpose).}
11
        {--force= : override the existing files}
12
    ';
13
14
	protected $description = 'Generates creation migration for a pivot table';
15
16
    protected $tables;
17
18
    public function handle()
19
    {
20
        $this->parseTables();
21
22
        $this->call('wn:migration', [
23
            'table' => implode('_', $this->tables),
24
            '--schema' => $this->schema(),
25
            '--keys' => $this->keys(),
26
            '--file' => $this->option('file'),
27
            '--parsed' => false,
28
            '--force' => $this->option('force'),
29
            '--add' => $this->option('add')
30
        ]);
31
    }
32
33
    protected function parseTables()
34
    {
35
        $this->tables = array_map(function($arg) {
36
            return \Illuminate\Support\Str::snake(\Illuminate\Support\Str::singular($this->argument($arg)));
0 ignored issues
show
Bug introduced by
It seems like $this->argument($arg) targeting Illuminate\Console\Command::argument() can also be of type array; however, Illuminate\Support\Str::singular() does only seem to accept string, 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...
37
        }, ['model1', 'model2']);
38
39
        sort($this->tables);
40
    }
41
42
    protected function schema()
43
    {
44
        return implode(' ', array_map(function($table){
45
            return $table . '_id:integer:unsigned:index';
46
        }, $this->tables));
47
    }
48
49
    protected function keys()
50
    {
51
        return implode(' ', array_map(function($table){
52
            return $table . '_id';
53
        }, $this->tables));
54
    }
55
56
}
57