Total Complexity | 8 |
Total Lines | 59 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 2 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
11 | class WithScoresModifier implements Modifier |
||
12 | { |
||
13 | |||
14 | /** |
||
15 | * @inheritDoc |
||
16 | * @throws Exception |
||
17 | */ |
||
18 | 17 | public static function process(array &$data) : array { |
|
19 | // Check for "single" export |
||
20 | 17 | if (isset($data['object'])) { |
|
21 | 9 | if (!$data['object'] instanceof Team) { |
|
22 | 1 | throw new InvalidArgumentException('WithScores modifier needs a Team object.'); |
|
23 | } |
||
24 | 8 | return self::processArray($data); |
|
25 | } |
||
26 | |||
27 | 8 | foreach ($data as $object) { |
|
28 | 8 | if (!isset($object->object) || !$object->object instanceof Team) { |
|
29 | 3 | throw new InvalidArgumentException('WithScores modifier needs a Team object.'); |
|
30 | } |
||
31 | 5 | self::processObject($object); |
|
32 | } |
||
33 | 5 | return $data; |
|
34 | } |
||
35 | |||
36 | /** |
||
37 | * Modify a "Single" data |
||
38 | * |
||
39 | * @param array $data |
||
40 | * |
||
41 | * @return array |
||
42 | * @throws Exception |
||
43 | */ |
||
44 | 8 | protected static function processArray(array &$data) : array { |
|
45 | /** @var Team $team */ |
||
46 | 8 | $team = $data['object']; |
|
47 | 8 | $data['scores'] = array_map(static function(array $group) { |
|
48 | 6 | unset($group['group']); // Get rid of the Group object reference |
|
49 | 6 | return $group; |
|
50 | 8 | }, $team->getGroupResults()); |
|
51 | 8 | return $data; |
|
52 | } |
||
53 | |||
54 | /** |
||
55 | * Modify data |
||
56 | * |
||
57 | * @param object $object |
||
58 | * |
||
59 | * @return object |
||
60 | * @throws Exception |
||
61 | */ |
||
62 | 5 | protected static function processObject(object $object) : object { |
|
70 | } |
||
71 | } |