Completed
Push — master ( aed5e6...e7b04e )
by Fumio
01:47
created

MigrationMakeCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 1
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 5
    public function __construct()
39
    {
40 5
        parent::__construct();
41
42 5
        $this->setStubDirectory(__DIR__.'/../../stubs');
43 5
    }
44
45
    /**
46
     * Get the default namespace for the class.
47
     *
48
     * @return string
49
     */
50 3
    protected function getDefaultNamespace()
51
    {
52 3
        return $this->getRootNamespace().'\\Database\\Migrations';
53
    }
54
55
    /**
56
     * Get the stub file for the generator.
57
     *
58
     * @return string
59
     */
60 3
    protected function getStub()
61
    {
62 3
        if ($this->option('create')) {
63 1
            return 'migration-create.stub';
64 2
        } elseif ($this->option('update')) {
65 1
            return 'migration-update.stub';
66
        } else {
67 1
            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 3
    protected function generateFile(FileGenerator $generator, $path, $fqcn)
81
    {
82 3
        list($namespace, $class) = $this->splitFullQualifyClassName($fqcn);
83
84 3
        return $generator->file($path)->template($this->getStub(), [
85 3
            'namespace' => $namespace,
86 3
            'class' => $class,
87 3
            'table' => $this->option('create') ?: $this->option('update'),
88
        ]);
89
    }
90
}
91