Completed
Push — feature/player-elo-v3 ( e6aec1 )
by Vladimir
02:55
created

PlayerElo::change()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 57
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 57
rs 9.6818
c 0
b 0
f 0
cc 1
eloc 44
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
        $matches = $this->table('matches');
13
        $matches
14
            ->addColumn('player_elo_diff', 'integer', [
15
                'after'   => 'elo_diff',
16
                'limit'   => 5,
17
                'signed'  => true,
18
                'null'    => true,
19
                'comment' => 'The change in ELO for players',
20
            ])
21
            ->update()
22
        ;
23
24
        $playerELOs = $this->table('player_elo', [
25
            'id' => false,
26
            'primary_key' => ['user_id', 'match_id']
27
        ]);
28
        $playerELOs
29
            ->addColumn('user_id', 'integer', [
30
                'limit'   => 10,
31
                'signed'  => false,
32
                'null'    => false,
33
                'comment' => 'The player whose had their individual ELO change',
34
            ])
35
            ->addColumn('match_id', 'integer', [
36
                'limit'   => 10,
37
                'signed'  => false,
38
                'null'    => false,
39
                'comment' => 'The match the player participated in, which resulted in this ELO change',
40
            ])
41
            ->addColumn('season_period', 'set', [
42
                'values'  => ['winter', 'spring', 'summer', 'fall'],
43
                'null'    => false,
44
                'comment' => 'The season this ELO change occurred in',
45
            ])
46
            ->addColumn('season_year', 'integer', [
47
                'limit'   => 4,
48
                'signed'  => false,
49
                'null'    => false,
50
                'comment' => 'The year of the season'
51
            ])
52
            ->addColumn('elo_previous', 'integer', [
53
                'signed'  => false,
54
                'null'    => false,
55
                'comment' => 'The ELO the player had prior to participating in this match',
56
            ])
57
            ->addColumn('elo_new', 'integer', [
58
                'signed'  => false,
59
                'null'    => false,
60
                'comment' => 'The new ELO for the player after participating in this match',
61
            ])
62
            ->addForeignKey('user_id', 'players', 'id', ['delete' => 'CASCADE'])
63
            ->addForeignKey('match_id', 'matches', 'id', ['delete' => 'CASCADE'])
64
            ->create()
65
        ;
66
    }
67
}
68