Conditions | 7 |
Paths | 12 |
Total Lines | 29 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
25 | public function completeFantasyOrder(array $fantasyOrder, array $cleanOrder): array |
||
26 | { |
||
27 | $lastFantasy = null; |
||
28 | $firstParameters = []; |
||
29 | $before = []; |
||
30 | |||
31 | // relation between param name et its place in the fantasy order |
||
32 | foreach ($cleanOrder as $param) { |
||
33 | if (in_array($param, $fantasyOrder)) { |
||
34 | $lastFantasy = $param; |
||
35 | continue; |
||
36 | } |
||
37 | if (($lastFantasy === null) && !in_array($param, $fantasyOrder)) { |
||
38 | $firstParameters[] = $param; |
||
39 | continue; |
||
40 | } |
||
41 | $before[$param] = $lastFantasy; |
||
42 | } |
||
43 | |||
44 | $result = $firstParameters; |
||
45 | foreach ($fantasyOrder as $param) { |
||
46 | $result[] = $param; |
||
47 | // additional parameters added in the end of the list |
||
48 | if (in_array($param, $before)) { |
||
49 | $result = array_merge($result, array_keys($before, $param)); |
||
50 | } |
||
51 | } |
||
52 | |||
53 | return $result; |
||
54 | } |
||
55 | } |