Completed
Push — feature/pixie-port ( 8213a1...132a2b )
by Vladimir
13:51
created

PlayerStatusColumnConversion   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 53
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
B up() 27 27 1
A down() 22 22 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 View Code Duplication
class PlayerStatusColumnConversion extends AbstractMigration
0 ignored issues
show
Duplication introduced by
This class 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...
6
{
7
    public function up()
8
    {
9
        $playersTable = $this->table('players');
10
        $playersTable
11
            ->addColumn('is_disabled', 'boolean', [
12
                'after' => 'last_login',
13
                'null' => false,
14
                'default' => false,
15
                'comment' => 'Whether or not this account has been disabled by an admin and cannot log in',
16
            ])
17
            ->addColumn('is_deleted', 'boolean', [
18
                'after' => 'is_disabled',
19
                'null' => false,
20
                'default' => false,
21
                'comment' => 'Whether or not this player has been soft-deleted',
22
            ])
23
            ->update()
24
        ;
25
26
        $this->query("UPDATE players SET is_deleted = 1 WHERE status = 'deleted';");
27
        $this->query("UPDATE players SET is_disabled = 1 WHERE status = 'disabled';");
28
29
        $playersTable
30
            ->removeColumn('status')
31
            ->update()
32
        ;
33
    }
34
35
    public function down()
36
    {
37
        $playersTable = $this->table('players');
38
        $playersTable
39
            ->addColumn('status', 'set', [
40
                'values' => ['active','disabled','deleted','reported','banned','test'],
41
                'null' => false,
42
                'default' => 'active',
43
                'comment' => 'The status of this player',
44
            ])
45
            ->update()
46
        ;
47
48
        $this->query("UPDATE players SET status = 'deleted' WHERE is_deleted = 1;");
49
        $this->query("UPDATE players SET status = 'disabled' WHERE is_disabled = 1;");
50
51
        $playersTable
52
            ->removeColumn('is_disabled')
53
            ->removeColumn('is_deleted')
54
            ->update()
55
        ;
56
    }
57
}
58