| Conditions | 1 |
| Paths | 1 |
| Total Lines | 57 |
| Code Lines | 44 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 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 |