Completed
Pull Request — master (#51)
by Konstantinos
04:39
created

SupportFunMatches   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 3
c 2
b 0
f 1
lcom 0
cbo 3
dl 0
loc 47
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B change() 0 44 3
1
<?php
2
3
use Phinx\Migration\AbstractMigration;
4
5
class SupportFunMatches extends AbstractMigration
6
{
7
    public function change()
8
    {
9
        $columnsToUpdate = array(
10
            'team_a' => 'Team 1 who played in this match',
11
            'team_b' => 'Team 2 who played in this match',
12
            'team_a_elo_new' => 'The new ELO for Team 1',
13
            'team_b_elo_new' => 'The new ELO for Team 2',
14
            'elo_diff' => 'The difference in ELO to Team 1'
15
        );
16
17
        $matches = $this->table('matches');
18
        $columns = $matches->getColumns();
19
20
        $matches->dropForeignKey(array('team_a', 'team_b'));
21
22
        foreach ($columns as $column)
23
        {
24
            if (in_array($column->getName(), array_keys($columnsToUpdate)))
25
            {
26
                $column->setOptions(array(
27
                    'null'    => true,
28
                    'signed'  => ($column->getName() == 'elo_diff'),
29
                    'comment' => $columnsToUpdate[$column->getName()]
30
                ));
31
32
                $matches->changeColumn($column->getName(), $column);
33
            }
34
        }
35
36
        $matches->addForeignKey('team_a', 'teams');
37
        $matches->addForeignKey('team_b', 'teams');
38
39
        $teamColorAssets = array('values'  => array('red', 'green', 'blue', 'purple'),
40
                                 'null'    => true,
41
                                 'comment' => 'The color of the team');
42
43
        $matches->addColumn('team_a_color', 'set', $teamColorAssets);
44
        $matches->addColumn('team_b_color', 'set', $teamColorAssets);
45
        $matches->addColumn('match_type', 'set', array('values' => array('official', 'fm', 'special'),
46
                                                       'null' => false,
47
                                                       'default' => 'official',
48
                                                       'comment' => 'The type of match that was played'));
49
        $matches->save();
50
    }
51
}
52