Total Complexity | 4 |
Total Lines | 42 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
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
|
|||
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 |
||
52 | * |
||
53 | * @return Category New category |
||
54 | */ |
||
55 | 8 | public function category(string $name = '', $id = null) : Category { |
|
59 | } |
||
60 | |||
61 | } |