Completed
Push — fm-matches ( f867e2 )
by Vladimir
16:54
created

SupportFunMatches::change()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 37
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 37
ccs 17
cts 17
cp 1
rs 8.8571
cc 3
eloc 24
nc 3
nop 0
crap 3
1
<?php
2
3
use Phinx\Migration\AbstractMigration;
4
5
class SupportFunMatches extends AbstractMigration
6
{
7 1
    public function change()
8
    {
9
        $columnsToUpdate = array(
10 1
            '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 1
        $matches = $this->table('matches');
18 1
        $columns = $matches->getColumns();
19
20 1
        $matches->dropForeignKey(array('team_a', 'team_b'));
21
22 1
        foreach ($columns as $column)
23
        {
24 1
            if (in_array($column->getName(), array_keys($columnsToUpdate)))
25
            {
26 1
                $column->setOptions(array(
27 1
                    'null'    => true,
28 1
                    'signed'  => ($column->getName() == 'elo_diff'),
29 1
                    'comment' => $columnsToUpdate[$column->getName()]
30
                ));
31
32 1
                $matches->changeColumn($column->getName(), $column);
33
            }
34
        }
35
36 1
        $matches->addForeignKey('team_a', 'teams');
37 1
        $matches->addForeignKey('team_b', 'teams');
38 1
        $matches->addColumn('match_type', 'set', array('values' => array('official', 'fm', 'special'),
39
                                                       'null' => false,
40
                                                       'default' => 'official',
41
                                                       'comment' => 'The type of match that was played'));
42 1
        $matches->save();
43 1
    }
44
}
45