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

GameExporter::start()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
/** @noinspection PhpDocFieldTypeMismatchInspection */
3
4
5
namespace TournamentGenerator\Export\Single;
6
7
use TournamentGenerator\Export\Export;
8
use TournamentGenerator\Export\SingleExportBase;
9
use TournamentGenerator\Game;
10
use TournamentGenerator\Interfaces\WithId;
11
12
/**
13
 * Exporter for games
14
 *
15
 * A specific exporter, taking care of games and their related data. Exports data from a single Game object.
16
 *
17
 * @package TournamentGenerator\Export
18
 * @author  Tomáš Vojík <[email protected]>
19
 * @since   0.5
20
 */
21
class GameExporter extends SingleExportBase
22
{
23
24
	/** @var Game */
25
	protected WithId $object;
26
27
	/**
28
	 * SingleGameExporter constructor.
29
	 *
30
	 * @param Game $game
31
	 *
32
	 * @noinspection MagicMethodsValidityInspection
33
	 * @noinspection PhpMissingParentConstructorInspection
34
	 */
35
	public function __construct(Game $game) {
36
		$this->object = $game;
37
	}
38
39
	/**
40
	 * Simple export query without any modifiers
41
	 *
42
	 * @param Game $object
43
	 *
44
	 * @return array
45
	 */
46
	public static function export(WithId $object) : array {
47
		return self::start($object)->get();
48
	}
49
50
	/**
51
	 * Start an export query
52
	 *
53
	 * @param Game $object
54
	 *
55
	 * @return Export
56
	 */
57
	public static function start(WithId $object) : Export {
58
		return new self($object);
59
	}
60
61
	/**
62
	 * Simple export query without any modifiers
63
	 *
64
	 * @param Game $object
65
	 *
66
	 * @return array The query result including the object reference
67
	 */
68
	public static function exportBasic(WithId $object) : array {
69
		return (new self($object))->getWithObject();
70
	}
71
72
	/**
73
	 * Gets the basic unmodified data
74
	 *
75
	 * @return array
76
	 */
77
	public function getBasic() : array {
78
		return [
79
			'object' => $this->object, // Passed for reference in the modifier methods
80
			'id'     => $this->object->getId(),
81
			'teams'  => $this->object->getTeamsIds(),
0 ignored issues
show
Bug introduced by
The method getTeamsIds() does not exist on TournamentGenerator\Interfaces\WithId. It seems like you code against a sub-type of TournamentGenerator\Interfaces\WithId such as TournamentGenerator\Game. ( Ignorable by Annotation )

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

81
			'teams'  => $this->object->/** @scrutinizer ignore-call */ getTeamsIds(),
Loading history...
82
			'scores' => $this->object->getResults(),
0 ignored issues
show
Bug introduced by
The method getResults() does not exist on TournamentGenerator\Interfaces\WithId. It seems like you code against a sub-type of TournamentGenerator\Interfaces\WithId such as TournamentGenerator\Game. ( Ignorable by Annotation )

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

82
			'scores' => $this->object->/** @scrutinizer ignore-call */ getResults(),
Loading history...
83
		];
84
	}
85
}