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