1
|
|
|
<?php |
2
|
|
|
/** @noinspection PhpDocFieldTypeMismatchInspection */ |
3
|
|
|
|
4
|
|
|
|
5
|
|
|
namespace TournamentGenerator\Export; |
6
|
|
|
|
7
|
|
|
use InvalidArgumentException; |
8
|
|
|
use TournamentGenerator\Game; |
9
|
|
|
use TournamentGenerator\HierarchyBase; |
10
|
|
|
use TournamentGenerator\Interfaces\WithGames; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Exporter for games |
14
|
|
|
* |
15
|
|
|
* A specific exporter, taking care of games and their related data. |
16
|
|
|
* |
17
|
|
|
* @package TournamentGenerator\Export |
18
|
|
|
* @author Tomáš Vojík <[email protected]> |
19
|
|
|
* @since 0.5 |
20
|
|
|
*/ |
21
|
|
|
class GameExporter extends ExportBase |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
/** @var WithGames */ |
25
|
|
|
protected HierarchyBase $object; |
26
|
|
|
|
27
|
8 |
|
public function __construct(HierarchyBase $object) { |
28
|
8 |
|
if (!$object instanceof WithGames) { |
29
|
1 |
|
throw new InvalidArgumentException('Object must be instance of WithGames.'); |
30
|
|
|
} |
31
|
7 |
|
parent::__construct($object); |
32
|
7 |
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Simple export query without any modifiers |
36
|
|
|
* |
37
|
|
|
* @param HierarchyBase $object |
38
|
|
|
* |
39
|
|
|
* @return array |
40
|
|
|
*/ |
41
|
3 |
|
public static function export(HierarchyBase $object) : array { |
42
|
3 |
|
return self::start($object)->get(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Start an export query |
47
|
|
|
* |
48
|
|
|
* @param HierarchyBase $object |
49
|
|
|
* |
50
|
|
|
* @return Export |
51
|
|
|
*/ |
52
|
8 |
|
public static function start(HierarchyBase $object) : Export { |
53
|
8 |
|
return new self($object); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Gets the basic unmodified data |
58
|
|
|
* |
59
|
|
|
* @return array |
60
|
|
|
*/ |
61
|
6 |
|
public function getBasic() : array { |
62
|
6 |
|
return array_map(static function(Game $game) { |
63
|
|
|
return (object) [ |
64
|
6 |
|
'object' => $game, // Passed for reference in the modifier methods |
65
|
6 |
|
'id' => $game->getId(), |
66
|
6 |
|
'teams' => $game->getTeamsIds(), |
67
|
6 |
|
'scores' => $game->getResults(), |
68
|
|
|
]; |
69
|
6 |
|
}, $this->object->getGames()); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.