Completed
Push — master ( e68441...354a44 )
by Vincenzo
02:20
created

CreateMigrationCommand::getHead()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 0
1
<?php
2
3
4
namespace App\Lib\Slime\Console\Commands;
5
6
7
use App\Lib\Helpers\TextFormatter;
8
use App\Lib\Slime\Console\GeneratorHelperCommand;
9
10
class CreateMigrationCommand extends GeneratorHelperCommand
11
{
12
    protected $incrementalFileName = null;
13
    protected $prefix = 'M'; //stands for migration
14
    protected $filePath = 'database/migrations/';
15
16
    protected function getFileName()
17
    {
18
        return $this->getIncrementalFileName();
19
    }
20
21
22
    protected function getHead()
23
    {
24
        $fileHead = parent::getHead();
25
        $fileHead .= PHP_EOL
26
            . PHP_EOL
27
            . 'use App\Lib\Slime\Interfaces\DatabaseHelpers\DbHelperInterface;'
28
            . PHP_EOL
29
            . 'use Illuminate\Database\Capsule\Manager as Capsule; '
30
            . PHP_EOL
31
            . 'use \Illuminate\Database\Schema\Blueprint as Blueprint;'
32
            . PHP_EOL;
33
        return $fileHead;
34
    }
35
36
    protected function getFilePath()
37
    {
38
        return $this->filePath;
39
    }
40
41 View Code Duplication
    protected function getStub()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
    {
43
        return PHP_EOL . 'class ' .
44
        $this->getIncrementalFileName() .
45
        ' implements DbHelperInterface {'
46
        . PHP_EOL
47
        . '
48
        public function run()
49
        {
50
        $tableName = \'table_name\';
51
        Capsule::schema()->dropIfExists($tableName);
52
        Capsule::schema()->create($tableName, function (Blueprint $table) {
53
            $table->increments(\'id\');
54
            $table->string(\'name\');
55
            $table->timestamps();
56
        });
57
        }
58
        '
59
        . PHP_EOL
60
        . '}';
61
    }
62
63
    protected function getIncrementalFileName()
64
    {
65
        if (empty($this->incrementalFileName)) {
66
            $this->incrementalFileName = $this->prefix . time() . TextFormatter::snakeToCamelCase($this->getArg(0));
67
        }
68
        return $this->incrementalFileName;
69
    }
70
71
72
}