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

WithGames::setGameAutoincrementId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
4
namespace TournamentGenerator\Traits;
5
6
7
use TournamentGenerator\Containers\GameContainer;
8
use TournamentGenerator\Game;
9
use TournamentGenerator\Interfaces\WithGames as WithGamesInterface;
10
11
/**
12
 * Trait WithGames
13
 *
14
 * @package TournamentGenerator\Traits
15
 * @author  Tomáš Vojík <[email protected]>
16
 * @since   0.4
17
 */
18
trait WithGames
19
{
20
	/** @var GameContainer List of games */
21
	protected GameContainer $games;
22
23
	/**
24
	 * Add a child container for games
25
	 *
26
	 * @param GameContainer $container
27
	 *
28
	 * @return WithGamesInterface
29
	 * @throws \Exception
30
	 */
31 70
	public function addGameContainer(GameContainer $container) : WithGamesInterface {
32 70
		$this->games->addChild($container);
33 70
		return $this;
34
	}
35
36
	/**
37
	 * Get all tournament games
38
	 *
39
	 * @return Game[]
40
	 */
41 53
	public function getGames() : array {
42 53
		return $this->games->get();
43
	}
44
45
	/**
46
	 * Get the container for games
47
	 *
48
	 * @return GameContainer
49
	 */
50 74
	public function getGameContainer() : GameContainer {
51 74
		return $this->games;
52
	}
53
54
	/**
55
	 * Sets a new autoincrement value (start) for the generated games
56
	 *
57
	 * @param int $id Id - probably from the database
58
	 *
59
	 * @warning Do this on the top-level hierarchy element (Tournament class) or else, it might be reset later
60
	 *
61
	 * @post Propagates the value to all child hierarchy objects
62
	 *
63
	 * @see GameContainer::setAutoIncrement()
64
	 *
65
	 * @return WithGamesInterface
66
	 * @since 0.5
67
	 */
68
	public function setGameAutoincrementId(int $id) : WithGamesInterface {
69
		$this->games->setAutoIncrement($id);
70
		return $this;
71
	}
72
}