Test Failed
Push — develop ( 92c10d...ff12cf )
by Daniel
05:05
created

Route::setName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Silverback\ApiComponentBundle\Entity\Route;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Collection;
9
use Doctrine\ORM\Mapping as ORM;
10
use Ramsey\Uuid\Uuid;
11
use Silverback\ApiComponentBundle\Entity\Content\AbstractContent;
12
use Silverback\ApiComponentBundle\Entity\Content\Page\Dynamic\DynamicContent;
13
use Silverback\ApiComponentBundle\Entity\Content\Page\StaticPage;
14
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
15
use Symfony\Component\Serializer\Annotation\Groups;
16
use Symfony\Component\Validator\Constraints as Assert;
17
18
/**
19
 * Class Route
20
 * @package Silverback\ApiComponentBundle\Entity
21
 * @author Daniel West <[email protected]>
22
 * @ORM\Entity(repositoryClass="Silverback\ApiComponentBundle\Repository\Route\RouteRepository")
23
 * @UniqueEntity(fields={"route"}, message="This route is already in use")
24
 */
25
class Route
26
{
27
    /**
28
     * @ORM\Id()
29
     * @ORM\Column(type="string")
30
     * @Groups({"route"})
31
     * @var string
32
     */
33
    private $id;
34
35
    /**
36
     * @ORM\Column(type="string", unique=true)
37
     * @Groups({"default"})
38
     * @var string
39
     */
40
    private $route;
41
42
    /**
43
     * @ORM\Column(type="string", unique=true)
44
     * @Groups({"route"})
45
     * @var string
46
     */
47
    private $name;
48
49
    /**
50
     * @ORM\ManyToOne(targetEntity="Silverback\ApiComponentBundle\Entity\Content\Page\Dynamic\DynamicContent", inversedBy="routes")
51
     * @ORM\JoinColumn(onDelete="SET NULL", nullable=true)
52
     * @Groups({"route"})
53
     * @Assert\Type("Silverback\ApiComponentBundle\Entity\Route\RouteAwareInterface")
54
     * @var null|DynamicContent
55
     */
56
    private $dynamicContent;
57
58
    /**
59
     * @ORM\ManyToOne(targetEntity="Silverback\ApiComponentBundle\Entity\Content\Page\StaticPage", inversedBy="routes")
60
     * @ORM\JoinColumn(onDelete="SET NULL", nullable=true)
61
     * @Groups({"route"})
62
     * @Assert\Type("Silverback\ApiComponentBundle\Entity\Route\RouteAwareInterface")
63
     * @var null|StaticPage
64
     */
65
    private $staticPage;
66
67
    /**
68
     * @ORM\ManyToOne(targetEntity="Silverback\ApiComponentBundle\Entity\Route\Route", inversedBy="redirectedFrom")
69
     * @ORM\JoinColumn(name="redirect", referencedColumnName="id", onDelete="SET NULL")
70
     * @Groups({"route_read"})
71
     * @var null|Route
72
     */
73
    private $redirect;
74
75
    /**
76
     * @ORM\OneToMany(targetEntity="Silverback\ApiComponentBundle\Entity\Route\Route", mappedBy="redirect")
77
     * @Groups({"route"})
78
     * @var Route[]|Collection
79
     */
80
    private $redirectedFrom;
81
82
    public function __construct(?string $name = null, ?string $route = null, ?Route $redirect = null)
83
    {
84
        $this->id = Uuid::uuid4()->getHex();
85
        $this->name = $name ?: Uuid::uuid4()->getHex();
86
        $this->route = $route ?: '/' . Uuid::uuid4()->getHex();
87
        $this->redirectedFrom = new ArrayCollection();
88
        $this->setRedirect($redirect);
89
    }
90
91
    public function getRedirectedFrom(): Collection
92
    {
93
        return $this->redirectedFrom;
94
    }
95
96
    /**
97
     * @return string
98
     */
99
    public function getId(): string
100
    {
101
        return $this->id;
102
    }
103
104
    /**
105
     * @return string
106
     */
107
    public function getName(): string
108
    {
109
        return $this->name;
110
    }
111
112
    /**
113
     * @param string $name
114
     * @return Route
115
     */
116
    public function setName(string $name): self
117
    {
118
        $this->name = $name;
119
        return $this;
120
    }
121
122
    /**
123
     * @return string
124
     */
125
    public function getRoute(): string
126
    {
127
        return $this->route;
128
    }
129
130
    /**
131
     * @param string $route
132
     * @return Route
133
     */
134
    public function setRoute(string $route): self
135
    {
136
        $this->route = $route;
137
        return $this;
138
    }
139
140
    public function getDynamicContent(): ?DynamicContent
141
    {
142
        return $this->dynamicContent;
143
    }
144
145
    public function setDynamicContent(?DynamicContent $dynamicContent): self
146
    {
147
        $this->dynamicContent = $dynamicContent;
148
        return $this;
149
    }
150
151
    public function getStaticPage(): ?StaticPage
152
    {
153
        return $this->staticPage;
154
    }
155
156
    public function setStaticPage(?StaticPage $staticPage): self
157
    {
158
        $this->staticPage = $staticPage;
159
        return $this;
160
    }
161
162
    /**
163
     * @return null|Route
164
     */
165
    public function getRedirect(): ?Route
166
    {
167
        return $this->redirect;
168
    }
169
170
    /**
171
     * @param null|Route $redirect
172
     * @return Route
173
     */
174
    public function setRedirect(?Route $redirect): self
175
    {
176
        $this->redirect = $redirect;
177
        return $this;
178
    }
179
180
    /**
181
     * @Groups({"route_write"})
182
     * @param null|Route $redirectRoute
183
     */
184
    public function setRedirectRoute(?Route $redirectRoute): void
185
    {
186
        $this->redirect = $redirectRoute;
187
    }
188
}
189