Completed
Push — master ( 24f3d8...c7f57e )
by Rafał
09:53
created

Route::getRouteName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 1
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of the Superdesk Web Publisher Content Bundle.
5
 *
6
 * Copyright 2016 Sourcefabric z.ú. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2016 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Bundle\ContentBundle\Model;
16
17
use Doctrine\Common\Collections\ArrayCollection;
18
use Doctrine\Common\Collections\Collection;
19
use Symfony\Cmf\Bundle\RoutingBundle\Model\Route as BaseRoute;
20
21
class Route extends BaseRoute implements RouteInterface
22
{
23
    use RouteTrait;
24
    use ArticlesAwareTrait;
25
26
    /**
27
     * @var int
28
     */
29
    protected $id;
30
31
    /**
32
     * @var RouteInterface
33
     */
34
    protected $parent;
35
36
    /**
37
     * @var Collection|RouteInterface[]
38
     */
39
    protected $children;
40
41
    /**
42
     * @var int
43
     */
44
    protected $lft;
45
46
    /**
47
     * @var int
48
     */
49
    protected $rgt;
50
51
    /**
52
     * @var int
53
     */
54
    protected $level;
55
56
    protected ?RedirectRouteInterface $redirectRoute = null;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected '?', expecting T_FUNCTION or T_CONST
Loading history...
57
58
    /**
59
     * Route constructor.
60
     */
61
    public function __construct()
62
    {
63
        $this->articles = new ArrayCollection();
64
        $this->children = new ArrayCollection();
65 104
66
        parent::__construct();
67 104
    }
68 104
69
    /**
70 104
     * {@inheritdoc}
71 104
     */
72
    public function getId()
73
    {
74
        return parent::getId();
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80
    public function getRouteName()
81
    {
82
        return $this->getName();
83
    }
84
85
    public function addArticle(ArticleInterface $article): void
86
    {
87
        if (!$this->articles->contains($article)) {
88
            $this->articles->add($article);
89
            $article->setRoute($this);
90
        }
91
    }
92 30
93
    /**
94 30
     * {@inheritdoc}
95
     */
96
    public function isRoot(): bool
97
    {
98
        return null === $this->parent;
99
    }
100
101
    /**
102
     * {@inheritdoc}
103
     */
104
    public function getRoot(): RouteInterface
105
    {
106
        throw new \Exception('Method not supported.');
107
    }
108
109
    /**
110
     * {@inheritdoc}
111
     */
112
    public function getParent()
113
    {
114
        return $this->parent;
115
    }
116
117
    /**
118
     * {@inheritdoc}
119
     */
120
    public function setParent(RouteInterface $parent = null)
121
    {
122
        $this->parent = $parent;
123
    }
124
125
    /**
126
     * @return Collection|RouteInterface[]
127
     */
128
    public function getChildren()
129
    {
130
        return $this->children;
131
    }
132
133
    /**
134
     * {@inheritdoc}
135
     */
136
    public function hasChild(RouteInterface $route): bool
137
    {
138
        return $this->children->contains($route);
139
    }
140
141
    /**
142
     * {@inheritdoc}
143
     */
144
    public function addChild(RouteInterface $route)
145
    {
146
        if (!$this->hasChild($route)) {
147
            $route->setParent($this);
148
            $this->children->add($route);
149
        }
150
    }
151
152
    /**
153
     * {@inheritdoc}
154
     */
155
    public function removeChild(RouteInterface $route)
156
    {
157
        if ($this->hasChild($route)) {
158
            $route->setParent(null);
159
            $this->children->removeElement($route);
160
        }
161
    }
162
163
    /**
164
     * {@inheritdoc}
165
     */
166
    public function getLeft(): int
167
    {
168
        return $this->lft;
169
    }
170
171
    /**
172
     * {@inheritdoc}
173
     */
174
    public function setLeft(int $left)
175
    {
176
        $this->lft = $left;
177
    }
178
179
    /**
180
     * {@inheritdoc}
181
     */
182
    public function getRight(): int
183
    {
184
        return $this->rgt;
185
    }
186
187
    public function setRight(int $right)
188
    {
189
        $this->rgt = $right;
190
    }
191
192
    /**
193
     * {@inheritdoc}
194
     */
195
    public function getLevel(): int
196
    {
197
        return $this->level;
198
    }
199
200
    /**
201
     * {@inheritdoc}
202
     */
203
    public function setLevel(int $level)
204
    {
205
        $this->level = $level;
206
    }
207
208
    /**
209
     * {@inheritdoc}
210
     */
211
    public function getParentId()
212
    {
213
        if (null !== $this->parent) {
214
            return (int) $this->parent->getId();
215
        }
216
    }
217
218
    public function __toString()
219
    {
220
        return $this->getName();
221
    }
222
223
    public function getRedirectRoute(): ?RedirectRouteInterface
224
    {
225
        return $this->redirectRoute;
226
    }
227
228
    public function setRedirectRoute(?RedirectRouteInterface $redirectRoute): void
229
    {
230
        $this->redirectRoute = $redirectRoute;
231
    }
232
}
233