Completed
Pull Request — master (#186)
by Vladimir
05:50 queued 02:55
created

BansStatusColumnConversion   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 46.67 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 0 20 1
A down() 21 21 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 BansStatusColumnConversion extends AbstractMigration
7
{
8
    public function up()
9
    {
10
        $bansTable = $this->table('bans');
11
        $bansTable
12
            ->addColumn('is_deleted', 'boolean', [
13
                'after' => 'is_soft_ban',
14
                'null' => false,
15
                'default' => false,
16
                'comment' => 'Whether or not the ban has been deleted',
17
            ])
18
            ->update()
19
        ;
20
21
        $this->query("UPDATE bans SET is_deleted = 1 WHERE status = 'deleted';");
22
23
        $bansTable
24
            ->removeColumn('status')
25
            ->update()
26
        ;
27
    }
28
29 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...
30
    {
31
        $bansTable = $this->table('bans');
32
        $bansTable
33
            ->addColumn('status', 'set', [
34
                'values' => ['public', 'hidden', 'deleted'],
35
                'after' => 'is_soft_ban',
36
                'null' => false,
37
                'default' => 'public',
38
                'comment' => 'The status of the ban element',
39
            ])
40
            ->update()
41
        ;
42
43
        $this->query("UPDATE bans SET status = 'deleted' WHERE is_deleted = true;");
44
45
        $bansTable
46
            ->removeColumn('is_deleted')
47
            ->update()
48
        ;
49
    }
50
}
51