Completed
Push — develop ( d5109f...d13d89 )
by Daniel
06:42
created

AbstractContent::addComponentLocation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
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 Symfony\Component\Serializer\Annotation\MaxDepth;
11
12
/**
13
 * Class AbstractContent
14
 * @package Silverback\ApiComponentBundle\Entity
15
 * @author Daniel West <[email protected]>
16
 * @ORM\Entity()
17
 * @ORM\Table(name="route_content")
18
 * @ORM\InheritanceType("SINGLE_TABLE")
19
 * @ORM\DiscriminatorColumn(name="type", type="string")
20
 * @ORM\DiscriminatorMap({
21
 *     "page" = "Silverback\ApiComponentBundle\Entity\Content\Page",
22
 *     "component_group" = "Silverback\ApiComponentBundle\Entity\Content\ComponentGroup",
23
 *     "article" = "Silverback\ApiComponentBundle\Entity\Content\Dynamic\ArticlePage"
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
     * @ORM\OrderBy({"sort"="ASC"})
38
     * @MaxDepth(40)
39
     * @var Collection|ComponentLocation[]
40
     */
41
    protected $componentLocations;
42
43 28
    public function __construct()
44
    {
45 28
        $this->id = Uuid::uuid4()->getHex();
46 28
        $this->componentLocations = new ArrayCollection;
47 28
    }
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 getComponentLocations(): Collection
61
    {
62 2
        return $this->componentLocations;
63
    }
64
65
    /**
66
     * @param ComponentLocation[]|iterable $componentLocations
67
     * @return AbstractContent
68
     */
69
    public function setComponentLocations(iterable $componentLocations): AbstractContent
70
    {
71
        $this->componentLocations = new ArrayCollection;
72
        /** @var ComponentLocation $componentLocation */
73
        foreach ($componentLocations as $componentLocation)
74
        {
75
            $this->componentLocations->add($componentLocation);
76
        }
77
        return $this;
78
    }
79
80
    /**
81
     * @param ComponentLocation $componentLocation
82
     * @return AbstractContent
83
     */
84 2
    public function addComponentLocation(ComponentLocation $componentLocation): AbstractContent
85
    {
86 2
        $this->componentLocations->add($componentLocation);
87 2
        return $this;
88
    }
89
90
    /**
91
     * @param ComponentLocation $componentLocation
92
     * @return AbstractContent
93
     */
94
    public function removeComponentLocation(ComponentLocation $componentLocation): AbstractContent
95
    {
96
        $this->componentLocations->removeElement($componentLocation);
97
        return $this;
98
    }
99
}
100