| Conditions | 14 |
| Paths | 257 |
| Total Lines | 39 |
| Code Lines | 32 |
| 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 |
||
| 94 | public static function savePreliminaryFightRound($rounds, $numRound = 1) |
||
| 95 | { |
||
| 96 | |||
| 97 | $c1 = $c2 = $c3 = null; |
||
|
|
|||
| 98 | $order = 0; |
||
| 99 | |||
| 100 | foreach ($rounds as $round) { |
||
| 101 | if ($round->championship->isTeam) { |
||
| 102 | $fighter1 = isset($round->teams[0]) ? $round->teams[0] : null; |
||
| 103 | $fighter2 = isset($round->teams[1]) ? $round->teams[1] : null; |
||
| 104 | $fighter3 = isset($round->teams[2]) ? $round->teams[2] : null; |
||
| 105 | } else { |
||
| 106 | $fighter1 = isset($round->competitors[0]) ? $round->competitors[0] : null; |
||
| 107 | $fighter2 = isset($round->competitors[1]) ? $round->competitors[1] : null; |
||
| 108 | $fighter3 = isset($round->competitors[2]) ? $round->competitors[2] : null; |
||
| 109 | } |
||
| 110 | switch ($numRound) { |
||
| 111 | case 1: |
||
| 112 | $c1 = $fighter1; |
||
| 113 | $c2 = $fighter2; |
||
| 114 | break; |
||
| 115 | case 2: |
||
| 116 | $c1 = $fighter2; |
||
| 117 | $c2 = $fighter3; |
||
| 118 | break; |
||
| 119 | case 3: |
||
| 120 | $c1 = $fighter3; |
||
| 121 | $c2 = $fighter1; |
||
| 122 | break; |
||
| 123 | } |
||
| 124 | $fight = new Fight(); |
||
| 125 | $fight->round_id = $round->id; |
||
| 126 | $fight->c1 = $c1 != null ? $c1->id : null; |
||
| 127 | $fight->c2 = $c2 != null ? $c2->id : null; |
||
| 128 | $fight->order = $order++; |
||
| 129 | $fight->area = $round->area; |
||
| 130 | $fight->save(); |
||
| 131 | } |
||
| 132 | } |
||
| 133 | |||
| 202 | } |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.