Completed
Push — master ( 5c3586...68bdab )
by Tomáš
02:53
created

GameExporter::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 2
rs 10
c 1
b 0
f 0
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());
0 ignored issues
show
Bug introduced by
The method getGames() does not exist on TournamentGenerator\HierarchyBase. Did you maybe mean getName()? ( Ignorable by Annotation )

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

69
		}, $this->object->/** @scrutinizer ignore-call */ getGames());

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.

Loading history...
70
	}
71
}