Completed
Pull Request — master (#186)
by Vladimir
06:00 queued 03:00
created

NewsStatusColumnConversion   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 62
Duplicated Lines 45.16 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 28
loc 62
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B down() 0 30 1
B up() 28 28 1

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
use Phinx\Migration\AbstractMigration;
5
6
class NewsStatusColumnConversion extends AbstractMigration
7
{
8 View Code Duplication
    public function up()
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...
9
    {
10
        $newsTable = $this->table('news');
11
        $newsTable
12
            ->addColumn('is_draft', 'boolean', [
13
                'after' => 'editor',
14
                'null' => false,
15
                'default' => false,
16
                'comment' => 'Whether or not the news article is a draft',
17
            ])
18
            ->addColumn('is_deleted', 'boolean', [
19
                'after' => 'is_draft',
20
                'null' => false,
21
                'default' => false,
22
                'comment' => 'Whether or not the news article has been soft deleted',
23
            ])
24
            ->update()
25
        ;
26
27
        $this->query("UPDATE news SET is_draft = 1 WHERE status = 'revision' OR status ='draft';");
28
        $this->query("UPDATE news SET is_deleted = 1 WHERE status = 'deleted' OR status = 'disabled';");
29
30
        $newsTable
31
            ->removeColumn('parent_id')
32
            ->removeColumn('status')
33
            ->update()
34
        ;
35
    }
36
37
    public function down()
38
    {
39
        $newsTable = $this->table('news');
40
        $newsTable
41
            ->addColumn('parent_id', 'integer', [
42
                'after' => 'id',
43
                'null' => true,
44
                'default' => null,
45
                'length' => 11,
46
                'comment' => 'The ID of the original news post. If this column is set, then it is a revision',
47
            ])
48
            ->addColumn('status', 'set', [
49
                'values' => ['published', 'revision', 'draft', 'disabled', 'deleted'],
50
                'after' => 'editor',
51
                'null' => false,
52
                'default' => 'published',
53
                'comment' => 'The status of the news element',
54
            ])
55
            ->update()
56
        ;
57
58
        $this->query("UPDATE news SET status = 'draft' WHERE is_draft = 1;");
59
        $this->query("UPDATE news SET status = 'deleted' WHERE is_deleted = 1;");
60
61
        $newsTable
62
            ->removeColumn('is_draft')
63
            ->removeColumn('is_deleted')
64
            ->update()
65
        ;
66
    }
67
}
68