Completed
Push — master ( a7ba40...b3dcaf )
by Tomáš
06:44
created

GamesExporter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getBasic() 0 4 1
A export() 0 2 1
A __construct() 0 5 2
A start() 0 2 1
1
<?php
2
/** @noinspection PhpDocFieldTypeMismatchInspection */
3
4
5
namespace TournamentGenerator\Export\Hierarchy;
6
7
use InvalidArgumentException;
8
use TournamentGenerator\Export\Export;
9
use TournamentGenerator\Export\ExportBase;
10
use TournamentGenerator\Export\Single\GameExporter;
11
use TournamentGenerator\Game;
12
use TournamentGenerator\HierarchyBase;
13
use TournamentGenerator\Interfaces\WithGames;
14
use TournamentGenerator\Interfaces\WithId;
15
16
/**
17
 * Exporter for games
18
 *
19
 * A specific exporter, taking care of games and their related data. Exports all games from a hierarchy object.
20
 *
21
 * @package TournamentGenerator\Export
22
 * @author  Tomáš Vojík <[email protected]>
23
 * @since   0.5
24
 */
25
class GamesExporter extends ExportBase
26
{
27
28
	/** @var Game */
29
	protected WithId $object;
30
31
	public function __construct(HierarchyBase $object) {
32
		if (!$object instanceof WithGames) {
33
			throw new InvalidArgumentException('Object must be instance of WithGames.');
34
		}
35
		parent::__construct($object);
36
	}
37
38
	/**
39
	 * Simple export query without any modifiers
40
	 *
41
	 * @param HierarchyBase $object
42
	 *
43
	 * @return array
44
	 */
45
	public static function export(WithId $object) : array {
46
		return self::start($object)->get();
47
	}
48
49
	/**
50
	 * Start an export query
51
	 *
52
	 * @param HierarchyBase $object
53
	 *
54
	 * @return Export
55
	 */
56
	public static function start(WithId $object) : Export {
57
		return new self($object);
58
	}
59
60
	/**
61
	 * Gets the basic unmodified data
62
	 *
63
	 * @return array
64
	 * @see GameExporter::export()
65
	 *
66
	 */
67
	public function getBasic() : array {
68
		return array_map(static function(Game $game) {
69
			return (object) GameExporter::exportBasic($game);
70
		}, $this->object->getGames());
0 ignored issues
show
Bug introduced by
The method getGames() does not exist on TournamentGenerator\Interfaces\WithId. It seems like you code against a sub-type of said class. However, the method does not exist in TournamentGenerator\Base or TournamentGenerator\Game or TournamentGenerator\HierarchyBase. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

70
		}, $this->object->/** @scrutinizer ignore-call */ getGames());
Loading history...
71
	}
72
}