Completed
Push — develop ( e72854...0832ef )
by Daniel
06:46
created

Route   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 149
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 14
eloc 27
dl 0
loc 149
ccs 0
cts 25
cp 0
rs 10
c 0
b 0
f 0

12 Methods

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