Completed
Push — feature/player-elo ( f5ce1b )
by Vladimir
02:36
created

PlayerElo   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A change() 0 49 1
1
<?php
2
3
use Phinx\Migration\AbstractMigration;
4
5
class PlayerElo extends AbstractMigration
6
{
7
    /**
8
     * {@inheritdoc}
9
     */
10
    public function change()
11
    {
12
        $players = $this->table('players');
13
        $players
14
            ->addColumn('elo', 'integer', [
15
                'limit' => 10,
16
                'signed' => false,
17
                'null' => false,
18
                'default' => 1200,
19
                'comment' => 'The current ELO for this player'
20
            ])
21
            ->update()
22
        ;
23
24
        $playerELOs = $this->table('player_elo', ['id' => false, 'primary_key' => 'id']);
25
        $playerELOs
26
            ->addColumn('id', 'integer', ['limit' => 10, 'signed' => false, 'identity' => true])
27
            ->addColumn('user_id', 'integer', [
28
                'limit' => 10,
29
                'signed' => false,
30
                'null' => false,
31
                'comment' => 'The player whose had their individual ELO change',
32
            ])
33
            ->addColumn('match_id', 'integer', [
34
                'limit' => 10,
35
                'signed' => false,
36
                'null' => false,
37
                'comment' => 'The match the player participated in, which resulted in this ELO change'
38
            ])
39
            ->addColumn('elo_diff', 'integer', [
40
                'signed' => false,
41
                'null' => false,
42
                'comment' => 'The change in ELO for this player from this match'
43
            ])
44
            ->addColumn('elo_previous', 'integer', [
45
                'signed' => false,
46
                'null' => false,
47
                'comment' => 'The ELO the player had prior to participating in this match'
48
            ])
49
            ->addColumn('elo_new', 'integer', [
50
                'signed' => false,
51
                'null' => false,
52
                'comment' => 'The new ELO for the player after participating in this match'
53
            ])
54
            ->addForeignKey('user_id', 'players', 'id', ['delete' => 'CASCADE'])
55
            ->addForeignKey('match_id', 'matches', 'id', ['delete' => 'CASCADE'])
56
            ->create()
57
        ;
58
    }
59
}
60