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

NewsCategoryStatusColumnConversion   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 59
Duplicated Lines 38.98 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
B up() 0 32 1
A down() 23 23 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
use Phinx\Migration\AbstractMigration;
4
5
class NewsCategoryStatusColumnConversion extends AbstractMigration
6
{
7
    public function up()
8
    {
9
        $newsCategoryTable = $this->table('news_categories');
10
        $newsCategoryTable
11
            ->addColumn('is_read_only', 'boolean', [
12
                'after' => 'protected',
13
                'null' => false,
14
                'default' => false,
15
                'comment' => 'When set to true, no new articles should be able to use this category'
16
            ])
17
            ->addColumn('is_deleted', 'boolean', [
18
                'after' => 'is_read_only',
19
                'null' => false,
20
                'default' => false,
21
                'comment' => 'Whether or not the news category has been soft deleted',
22
            ])
23
            ->changeColumn('protected', 'boolean', [
24
                'default' => false,
25
                'null' => false,
26
                'comment' => 'When set to true, prevents the category from being deleted from the UI',
27
            ])
28
            ->update()
29
        ;
30
31
        $this->query("UPDATE news_categories SET is_deleted = 1 WHERE status = 'deleted';");
32
33
        $newsCategoryTable
34
            ->removeColumn('status')
35
            ->renameColumn('protected', 'is_protected')
36
            ->update()
37
        ;
38
    }
39
40 View Code Duplication
    public function down()
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...
41
    {
42
        $newsCategoryTable = $this->table('news_categories');
43
        $newsCategoryTable
44
            ->addColumn('status', 'set', [
45
                'values' => ['enabled', 'disabled', 'deleted'],
46
                'after' => 'is_deleted',
47
                'null' => false,
48
                'default' => 'enabled',
49
                'comment' => 'The status of the news element',
50
            ])
51
            ->renameColumn('is_protected', 'protected')
52
            ->update()
53
        ;
54
55
        $this->query("UPDATE news_categories SET status = 'deleted' WHERE is_deleted = 1;");
56
57
        $newsCategoryTable
58
            ->removeColumn('is_deleted')
59
            ->removeColumn('is_read_only')
60
            ->update()
61
        ;
62
    }
63
}
64