Test Failed
Branch develop (ac2838)
by Daniel
09:09
created

AbstractNavigation   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A addItem() 0 4 1
A getId() 0 3 1
A getItems() 0 3 1
A setItems() 0 7 2
A removeItem() 0 4 1
A __construct() 0 4 1
1
<?php
2
3
namespace Silverback\ApiComponentBundle\Entity\Navigation;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\Common\Collections\Collection;
7
use Doctrine\ORM\Mapping as ORM;
8
use Ramsey\Uuid\Uuid;
9
use Symfony\Component\Serializer\Annotation\Groups;
10
11
/**
12
 * Class AbstractNavigation
13
 * @package Silverback\ApiComponentBundle\Entity\Navigation
14
 * @author Daniel West <[email protected]>
15
 * @ORM\Entity()
16
 * @ORM\Table(name="navigation")
17
 * @ORM\InheritanceType("SINGLE_TABLE")
18
 * @ORM\DiscriminatorColumn(name="type", type="string")
19
 * @ORM\DiscriminatorMap({
20
 *     "nav_bar" = "Silverback\ApiComponentBundle\Entity\Layout\NavBar\NavBar",
21
 *     "tabs" = "Silverback\ApiComponentBundle\Entity\Component\Navigation\Tabs\Tabs",
22
 *     "menu" = "Silverback\ApiComponentBundle\Entity\Component\Navigation\Menu\Menu"
23
 * })
24
 */
25
abstract class AbstractNavigation implements NavigationInterface
26
{
27
    /**
28
     * @ORM\Id()
29
     * @ORM\Column(type="string")
30
     * @var string
31
     */
32
    protected $id;
33
34
    /**
35
     * @ORM\OneToMany(targetEntity="Silverback\ApiComponentBundle\Entity\Navigation\AbstractNavigationItem", mappedBy="navigation")
36
     * @Groups({"layout", "content", "component"})
37
     * @var Collection|AbstractNavigationItem[]
38
     */
39
    protected $items;
40
41
    public function __construct()
42
    {
43
        $this->id = Uuid::uuid4()->getHex();
44
        $this->items = new ArrayCollection;
45
    }
46
47
    public function getId(): string
48
    {
49
        return $this->id;
50
    }
51
52
    public function getItems()
53
    {
54
        return $this->items;
55
    }
56
57
    public function setItems(array $items): AbstractNavigation
58
    {
59
        $this->items = new ArrayCollection;
60
        foreach ($items as $item) {
61
            $this->addItem($item);
62
        }
63
        return $this;
64
    }
65
66
    public function addItem(AbstractNavigationItem $navigationItem): AbstractNavigation
67
    {
68
        $this->items->add($navigationItem);
69
        return $this;
70
    }
71
72
    public function removeItem(AbstractNavigationItem $navigationItem): AbstractNavigation
73
    {
74
        $this->items->removeElement($navigationItem);
75
        return $this;
76
    }
77
}
78