Conditions | 4 |
Paths | 5 |
Total Lines | 24 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | 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 | $homeCount = count($home); |
||
19 | for ($j = 0; $j < $homeCount; $j++) { |
||
20 | $rounds[$i][$j]["home_team_id"] = $home[$j]['id']; |
||
21 | $rounds[$i][$j]["away_team_id"] = $away[$j]['id']; |
||
22 | } |
||
23 | if (count($home) + count($away) - 1 > 2) { |
||
24 | $spliced = array_splice($home, 1, 1); |
||
25 | $shifted = array_shift($spliced); |
||
26 | array_unshift($away, $shifted); |
||
27 | array_push($home, array_pop($away)); |
||
28 | } |
||
29 | } |
||
30 | return $rounds; |
||
31 | } |
||
32 | } |