Passed
Push — master ( 795926...7012fc )
by Tomáš
11:11
created

WithCategories   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A category() 0 4 1
A addCategory() 0 5 2
A getCategories() 0 2 1
1
<?php
2
3
4
namespace TournamentGenerator\Traits;
5
6
7
use TournamentGenerator\Category;
8
use TournamentGenerator\Interfaces\WithCategories as WithCategoriesInterface;
9
10
/**
11
 * Definitions of methods for objects that contain categories
12
 *
13
 * @author  Tomáš Vojík <[email protected]>
14
 * @package TournamentGenerator\Traits
15
 * @since   0.4
16
 */
17
trait WithCategories
18
{
19
20
	/** @var Category[] */
21
	protected array $categories = [];
22
23
	/**
24
	 * Get all categories
25
	 *
26
	 * @return Category[]
27
	 */
28 36
	public function getCategories() : array {
29 36
		return $this->categories;
30
	}
31
32
33
	/**
34
	 * Add one or more category to object
35
	 *
36
	 * @param Category ...$categories Category objects
37
	 *
38
	 * @return $this
39
	 */
40 1
	public function addCategory(Category ...$categories) : WithCategoriesInterface {
41 1
		foreach ($categories as $category) {
42 1
			$this->categories[] = $category;
43
		}
44 1
		return $this;
1 ignored issue
show
Bug Best Practice introduced by
The expression return $this returns the type TournamentGenerator\Traits\WithCategories which is incompatible with the type-hinted return TournamentGenerator\Interfaces\WithCategories.
Loading history...
45
	}
46
47
	/**
48
	 * Creates a new category and adds it to the object
49
	 *
50
	 * @param string $name New category name
51
	 * @param null   $id   Id of the new category - if omitted -> it is generated automatically as unique string
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $id is correct as it would always require null to be passed?
Loading history...
52
	 *
53
	 * @return Category New category
54
	 */
55 8
	public function category(string $name = '', $id = null) : Category {
56 8
		$c = new Category($name, $id);
57 8
		$this->categories[] = $c->setSkip($this->allowSkip);
58 8
		return $c;
59
	}
60
61
}