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

TeamsExporter   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 65
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A export() 0 2 1
A start() 0 2 1
A __construct() 0 5 2
A withScores() 0 3 1
A getBasic() 0 4 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\Modifiers\WithScoresModifier;
11
use TournamentGenerator\Export\Single\TeamExporter;
12
use TournamentGenerator\HierarchyBase;
13
use TournamentGenerator\Interfaces\WithId;
14
use TournamentGenerator\Interfaces\WithTeams;
15
use TournamentGenerator\Team;
16
17
/**
18
 * Exporter for teams
19
 *
20
 * A specific exporter for teams and their related data. Exports all teams from a hierarchy object.
21
 *
22
 * @package TournamentGenerator\Export
23
 * @author  Tomáš Vojík <[email protected]>
24
 * @since   0.5
25
 */
26
class TeamsExporter extends ExportBase
27
{
28
29
	/** @var WithTeams */
30
	protected WithId $object;
31
32
	/**
33
	 * TeamExporter constructor.
34
	 *
35
	 * @param HierarchyBase $object
36
	 */
37
	public function __construct(HierarchyBase $object) {
38
		if (!$object instanceof WithTeams) {
39
			throw new InvalidArgumentException('Object must be instance of WithTeams.');
40
		}
41
		parent::__construct($object);
42
	}
43
44
	/**
45
	 * Simple export query without any modifiers
46
	 *
47
	 * @param HierarchyBase $object
48
	 *
49
	 * @return array
50
	 */
51
	public static function export(WithId $object) : array {
52
		return self::start($object)->get();
53
	}
54
55
	/**
56
	 * Start an export query
57
	 *
58
	 * @param HierarchyBase $object
59
	 *
60
	 * @return Export
61
	 */
62
	public static function start(WithId $object) : Export {
63
		return new self($object);
64
	}
65
66
	/**
67
	 * Gets the basic unmodified data
68
	 *
69
	 * @return array
70
	 */
71
	public function getBasic() : array {
72
		return array_map(static function(Team $team) {
73
			return (object) TeamExporter::exportBasic($team);
74
		}, $this->object->getTeams());
0 ignored issues
show
Bug introduced by
The method getTeams() 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\HierarchyBase or TournamentGenerator\Team or TournamentGenerator\BlankTeam. 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

74
		}, $this->object->/** @scrutinizer ignore-call */ getTeams());
Loading history...
75
	}
76
77
	/**
78
	 * @defgroup TeamExporterQueryModifiers Query modifiers
79
	 * @brief    Modifier methods for the query
80
	 */
81
82
	/**
83
	 * Include team scores in the result set
84
	 *
85
	 * @return TeamsExporter
86
	 * @ingroup TeamExporterQueryModifiers
87
	 */
88
	public function withScores() : TeamsExporter {
89
		$this->modifiers[] = WithScoresModifier::class;
90
		return $this;
91
	}
92
}