Passed
Push — master ( a29a7e...12a432 )
by Mihail
08:06
created

update_cms_301   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 19.23 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 10
loc 52
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A seed() 0 2 1
A up() 0 16 3
A down() 0 13 3

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
use Ffcms\Core\Migrations\MigrationInterface;
4
use Ffcms\Core\Migrations\Migration;
5
6
/**
7
 * Class update_cms_301.
8
 */
9
class update_cms_301 extends Migration implements MigrationInterface
10
{
11
    /**
12
     * Add database changes, provided in time between 3.0.0 and 3.0.1 release is done
13
     * @return void
14
     */
15
    public function up()
16
    {
17
        // use important column for content app
18
        if (!$this->getSchema()->hasColumn('contents', 'important')) {
19
            $this->getSchema()->table('contents', function ($table) {
20
                $table->boolean('important')->default(false);
21
            });
22
        }
23
        // add group display color features
24
        if (!$this->getSchema()->hasColumn('roles', 'color')) {
25
            $this->getSchema()->table('roles', function ($table) {
26
                $table->string('color')->default('#777777');
27
            });
28
        }
29
30
        parent::up();
31
    }
32
33
    /**
34
     * Seed created table via up() method with some data
35
     * @return void
36
     */
37
    public function seed()
38
    {
39
40
    }
41
42
    /**
43
     * Execute actions when migration is down
44
     * @return void
45
     */
46
    public function down()
47
    {
48
        if ($this->getSchema()->hasColumn('contents', 'important')) {
49
            $this->getSchema()->table('contents', function ($table) {
50
                $table->dropColumn('important');
51
            });
52
        }
53
        if ($this->getSchema()->hasColumn('roles', 'color')) {
54
            $this->getSchema()->table('roles', function ($table) {
55
                $table->dropColumn('color');
56
            });
57
        }
58
        parent::down();
59
    }
60
}