| Conditions | 4 |
| Paths | 5 |
| Total Lines | 21 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 8 | public static function generate(array $teams) |
||
| 9 | { |
||
| 10 | $numTeams = count($teams); |
||
| 11 | $numRounds = ($numTeams - 1); |
||
| 12 | $halfSize = $numTeams / 2; |
||
| 13 | |||
| 14 | $away = array_splice($teams, $halfSize); |
||
| 15 | $home = $teams; |
||
| 16 | $rounds = []; |
||
| 17 | for ($i = 0; $i < $numRounds ; $i++) { |
||
| 18 | for ($j = 0; $j < count($home); $j++) { |
||
|
|
|||
| 19 | $rounds[$i][$j]["home_team_id"] = $home[$j]['id']; |
||
| 20 | $rounds[$i][$j]["away_team_id"] = $away[$j]['id']; |
||
| 21 | } |
||
| 22 | if (count($home) + count($away) - 1 > 2) { |
||
| 23 | array_unshift($away, array_shift(array_splice($home, 1, 1))); |
||
| 24 | array_push($home, array_pop($away)); |
||
| 25 | } |
||
| 26 | } |
||
| 27 | return $rounds; |
||
| 28 | } |
||
| 29 | } |
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: