TreeItemTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 37
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setParent() 0 3 1
A addChild() 0 3 1
A getParent() 0 3 1
A getChildren() 0 3 1
1
<?php
2
3
namespace WebComplete\core\utils\tree;
4
5
use WebComplete\core\entity\AbstractEntity;
6
7
trait TreeItemTrait
8
{
9
    /** @var self|null */
10
    protected $parent;
11
    /** @var self[] */
12
    protected $children = [];
13
14
    /**
15
     * @param self|AbstractEntity $item
16
     */
17
    public function setParent(AbstractEntity $item)
18
    {
19
        $this->parent = $item;
0 ignored issues
show
Documentation Bug introduced by
It seems like $item of type WebComplete\core\entity\AbstractEntity is incompatible with the declared type null|WebComplete\core\utils\tree\TreeItemTrait of property $parent.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
20
    }
21
22
    /**
23
     * @return self|null
24
     */
25
    public function getParent()
26
    {
27
        return $this->parent;
28
    }
29
30
    /**
31
     * @param self|AbstractEntity $item
32
     */
33
    public function addChild(AbstractEntity $item)
34
    {
35
        $this->children[$item->getId()] = $item;
36
    }
37
38
    /**
39
     * @return self[]
40
     */
41
    public function getChildren(): array
42
    {
43
        return $this->children;
44
    }
45
}
46