Completed
Push — master ( c3f0f6...0c6e4d )
by Tomáš
02:30
created

HierarchyBase   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 9
c 1
b 0
f 0
dl 0
loc 34
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A insertIntoContainer() 0 9 5
A getContainer() 0 2 1
1
<?php
2
3
4
namespace TournamentGenerator;
5
6
7
use TournamentGenerator\Containers\HierarchyContainer;
8
use TournamentGenerator\Interfaces\WithGames as WithGamesInterface;
9
use TournamentGenerator\Interfaces\WithTeams as WithTeamsInterface;
10
11
/**
12
 * Class HierarchyBase
13
 *
14
 * Extended base for hierarchy objects (Tournament, Category, Round, Group).
15
 *
16
 * @package TournamentGenerator
17
 * @author Tomáš Vojík <[email protected]>
18
 */
19
abstract class HierarchyBase extends Base
20
{
21
22
	protected HierarchyContainer $container;
23
24
	/**
25
	 * Get the hierarchy container
26
	 *
27
	 * @return HierarchyContainer
28
	 */
29 76
	public function getContainer() : HierarchyContainer {
30 76
		return $this->container;
31
	}
32
33
	/**
34
	 * Insert into hierarchical container
35
	 *
36
	 * @param Base $object
37
	 *
38
	 * @post Object is added to hierarchy
39
	 * @post If the object has teams -> add other team container to hierarchy
40
	 * @post If the object has games -> add other game container to hierarchy
41
	 *
42
	 * @return $this
43
	 */
44 64
	public function insertIntoContainer(Base $object) : Base {
45 64
		$this->container->insert($object);
46 64
		if ($this instanceof WithGamesInterface && $object instanceof WithGamesInterface) {
47 64
			$this->addGameContainer($object->getGameContainer());
48
		}
49 64
		if ($this instanceof WithTeamsInterface && $object instanceof WithTeamsInterface) {
50 64
			$this->addTeamContainer($object->getTeamContainer());
51
		}
52 64
		return $this;
53
	}
54
55
}