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

TeamExporter::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\Modifiers\WithScoresModifier;
9
use TournamentGenerator\Export\SingleExportBase;
10
use TournamentGenerator\Interfaces\WithId;
11
use TournamentGenerator\Team;
12
13
/**
14
 * Exporter for teams
15
 *
16
 * A specific exporter, taking care of teams and their related data. Exports a single team object.
17
 *
18
 * @package TournamentGenerator\Export
19
 * @author  Tomáš Vojík <[email protected]>
20
 * @since   0.5
21
 */
22
class TeamExporter extends SingleExportBase
23
{
24
25
	/** @var Team */
26
	protected WithId $object;
27
28
	/**
29
	 * SingleTeamExporter constructor.
30
	 *
31
	 * @param Team $game
32
	 *
33
	 * @noinspection MagicMethodsValidityInspection
34
	 * @noinspection PhpMissingParentConstructorInspection
35
	 */
36
	public function __construct(Team $game) {
37
		$this->object = $game;
38
	}
39
40
	/**
41
	 * Simple export query without any modifiers
42
	 *
43
	 * @param Team $object
44
	 *
45
	 * @return array
46
	 */
47
	public static function export(WithId $object) : array {
48
		return self::start($object)->get();
49
	}
50
51
	/**
52
	 * Start an export query
53
	 *
54
	 * @param Team $object
55
	 *
56
	 * @return Export
57
	 */
58
	public static function start(WithId $object) : Export {
59
		return new self($object);
60
	}
61
62
	/**
63
	 * Simple export query without any modifiers
64
	 *
65
	 * @param Team $object
66
	 *
67
	 * @return array The query result including the object reference
68
	 */
69
	public static function exportBasic(WithId $object) : array {
70
		return (new self($object))->getWithObject();
71
	}
72
73
	/**
74
	 * @defgroup TeamExporterQueryModifiers Query modifiers
75
	 * @brief    Modifier methods for the query
76
	 */
77
78
	/**
79
	 * Gets the basic unmodified data
80
	 *
81
	 * @return array
82
	 */
83
	public function getBasic() : array {
84
		return [
85
			'object' => $this->object, // Passed for reference in the modifier methods
86
			'id'     => $this->object->getId(),
87
			'name'   => $this->object->getName(),
0 ignored issues
show
Bug introduced by
The method getName() does not exist on TournamentGenerator\Interfaces\WithId. It seems like you code against a sub-type of TournamentGenerator\Interfaces\WithId such as TournamentGenerator\Base. ( Ignorable by Annotation )

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

87
			'name'   => $this->object->/** @scrutinizer ignore-call */ getName(),
Loading history...
88
		];
89
	}
90
91
	/**
92
	 * Include team scores in the result set
93
	 *
94
	 * @return TeamExporter
95
	 * @ingroup TeamExporterQueryModifiers
96
	 */
97
	public function withScores() : TeamExporter {
98
		$this->modifiers[] = WithScoresModifier::class;
99
		return $this;
100
	}
101
}