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

CreateMigrationCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 33.33 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 21
loc 63
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getFileName() 0 4 1
A getHead() 0 13 1
A getFilePath() 0 4 1
A getStub() 21 21 1
A getIncrementalFileName() 0 7 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}