MigrationMakeCommand   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 22.22%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 83
ccs 4
cts 18
cp 0.2222
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getDefaultNamespace() 0 4 1
A getStub() 0 10 3
A generateFile() 0 10 2
1
<?php
2
3
namespace Jumilla\Versionia\Laravel\Commands;
4
5
use Jumilla\Generators\Laravel\OneFileGeneratorCommand as BaseCommand;
6
use Jumilla\Generators\FileGenerator;
7
8
class MigrationMakeCommand extends BaseCommand
9
{
10
    /**
11
     * The console command singature.
12
     *
13
     * @var stringphp
14
     */
15
    protected $signature = 'make:migration
16
        {name : The name of the class}
17
        {--create= : The table to be created}
18
        {--update= : The table to be updated}
19
    ';
20
21
    /**
22
     * The console command description.
23
     *
24
     * @var string
25
     */
26
    protected $description = 'Create a new migration class';
27
28
    /**
29
     * The type of class being generated.
30
     *
31
     * @var string
32
     */
33
    protected $type = 'Migration';
34
35
    /**
36
     * The constructor.
37
     */
38 2
    public function __construct()
39
    {
40 2
        parent::__construct();
41
42 2
        $this->setStubDirectory(__DIR__.'/../../stubs');
43 2
    }
44
45
    /**
46
     * Get the default namespace for the class.
47
     *
48
     * @return string
49
     */
50
    protected function getDefaultNamespace()
51
    {
52
        return $this->getRootNamespace().'\\Database\\Migrations';
53
    }
54
55
    /**
56
     * Get the stub file for the generator.
57
     *
58
     * @return string
59
     */
60
    protected function getStub()
61
    {
62
        if ($this->option('create')) {
63
            return 'migration-create.stub';
64
        } elseif ($this->option('update')) {
65
            return 'migration-update.stub';
66
        } else {
67
            return 'migration.stub';
68
        }
69
    }
70
71
    /**
72
     * Generate file.
73
     *
74
     * @param FileGenerator $generator
75
     * @param string        $path
76
     * @param string        $fqcn
77
     *
78
     * @return bool
79
     */
80
    protected function generateFile(FileGenerator $generator, $path, $fqcn)
81
    {
82
        list($namespace, $class) = $this->splitFullQualifyClassName($fqcn);
83
84
        return $generator->file($path)->template($this->getStub(), [
85
            'namespace' => $namespace,
86
            'class' => $class,
87
            'table' => $this->option('create') ?: $this->option('update'),
88
        ]);
89
    }
90
}
91