Passed
Push — develop ( f08141...fbab06 )
by Daniel
04:49
created

AbstractContent   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 64.29%

Importance

Changes 0
Metric Value
dl 0
loc 57
ccs 9
cts 14
cp 0.6429
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

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