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

BansStatusColumnConversion::down()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.3142
c 0
b 0
f 0
cc 1
eloc 14
nc 1
nop 0
1
<?php
2
3
4
use Phinx\Migration\AbstractMigration;
5
6
class BansStatusColumnConversion 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
        $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 banned',
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
    public function down()
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