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

WithGames   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 70%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 53
ccs 7
cts 10
cp 0.7
rs 10
c 2
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setGameAutoincrementId() 0 3 1
A getGames() 0 2 1
A getGameContainer() 0 2 1
A addGameContainer() 0 3 1
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
}