Passed
Push — develop ( 185343...eb895f )
by Daniel
06:30
created

AbstractContent::getComponentLocations()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
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
            $this->componentLocations->add($componentLocation);
75
        }
76
        return $this;
77
    }
78
79
    /**
80
     * @param ComponentLocation $componentLocation
81
     * @return AbstractContent
82
     */
83 2
    public function addComponentLocation(ComponentLocation $componentLocation): AbstractContent
84
    {
85 2
        $this->componentLocations->add($componentLocation);
86 2
        return $this;
87
    }
88
89
    /**
90
     * @param ComponentLocation $componentLocation
91
     * @return AbstractContent
92
     */
93
    public function removeComponentLocation(ComponentLocation $componentLocation): AbstractContent
94
    {
95
        $this->componentLocations->removeElement($componentLocation);
96
        return $this;
97
    }
98
}
99