Passed
Push — develop ( e0f0df...fa4b42 )
by Daniel
05:31
created

AbstractContent::getId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Silverback\ApiComponentBundle\Entity\Content;
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 Silverback\ApiComponentBundle\Entity\Content\Component\ComponentLocation;
10
use Silverback\ApiComponentBundle\Entity\Route\RouteAwareTrait;
11
use Symfony\Component\Serializer\Annotation\Groups;
12
use Symfony\Component\Serializer\Annotation\MaxDepth;
13
14
/**
15
 * Class AbstractContent
16
 * @package Silverback\ApiComponentBundle\Entity
17
 * @author Daniel West <[email protected]>
18
 * @ORM\Entity()
19
 * @ORM\Table(name="route_content")
20
 * @ORM\InheritanceType("SINGLE_TABLE")
21
 * @ORM\DiscriminatorColumn(name="type", type="string")
22
 * @ORM\DiscriminatorMap({
23
 *     "page" = "Silverback\ApiComponentBundle\Entity\Content\Page",
24
 *     "component_group" = "Silverback\ApiComponentBundle\Entity\Content\ComponentGroup"
25
 * })
26
 */
27
abstract class AbstractContent implements ContentInterface
28
{
29
    use RouteAwareTrait;
30
31
    /**
32
     * @ORM\Id()
33
     * @ORM\Column(type="string")
34
     * @var string
35
     */
36
    protected $id;
37
38
    /**
39
     * @ORM\OneToMany(targetEntity="Silverback\ApiComponentBundle\Entity\Content\Component\ComponentLocation", mappedBy="content", cascade={"persist", "remove"})
40
     * @Groups({"content", "route"})
41
     * @MaxDepth(10)
42
     * @var Collection|ComponentLocation[]
43
     */
44
    protected $components;
45
46 20
    public function __construct()
47
    {
48 20
        $this->routes = new ArrayCollection;
49 20
        $this->id = Uuid::uuid4()->getHex();
50 20
        $this->components = new ArrayCollection;
51 20
    }
52
53
    /**
54
     * @return string
55
     */
56
    public function getId(): string
57
    {
58
        return $this->id;
59
    }
60
61
    /**
62
     * @return Collection|ComponentLocation[]
63
     */
64 1
    public function getComponents(): Collection
65
    {
66 1
        return $this->components;
67
    }
68
69
    /**
70
     * @param ComponentLocation $component
71
     * @return AbstractContent
72
     */
73
    public function addComponent(ComponentLocation $component): AbstractContent
74
    {
75
        $this->components->add($component);
76
        return $this;
77
    }
78
79
    /**
80
     * @param ComponentLocation $component
81
     * @return AbstractContent
82
     */
83
    public function removeComponent(ComponentLocation $component): AbstractContent
84
    {
85
        $this->components->removeElement($component);
86
        return $this;
87
    }
88
}
89