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
|
|
View Code Duplication |
class Route extends BaseRoute implements RouteInterface |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
use RouteTrait; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var int |
27
|
|
|
*/ |
28
|
|
|
protected $id; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var Collection |
32
|
|
|
*/ |
33
|
|
|
protected $articles; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var RouteInterface |
37
|
|
|
*/ |
38
|
|
|
protected $root; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var RouteInterface |
42
|
|
|
*/ |
43
|
|
|
protected $parent; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var Collection|RouteInterface[] |
47
|
|
|
*/ |
48
|
|
|
protected $children; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var int |
52
|
|
|
*/ |
53
|
|
|
protected $lft; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var int |
57
|
|
|
*/ |
58
|
|
|
protected $rgt; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var int |
62
|
|
|
*/ |
63
|
|
|
protected $level; |
64
|
|
|
|
65
|
68 |
|
public function __construct() |
66
|
|
|
{ |
67
|
68 |
|
$this->articles = new ArrayCollection(); |
68
|
68 |
|
$this->children = new ArrayCollection(); |
69
|
|
|
|
70
|
68 |
|
parent::__construct(); |
71
|
68 |
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* {@inheritdoc} |
75
|
|
|
*/ |
76
|
|
|
public function getArticles() |
77
|
|
|
{ |
78
|
|
|
return $this->articles; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* {@inheritdoc} |
83
|
|
|
*/ |
84
|
|
|
public function setArticles($articles) |
85
|
|
|
{ |
86
|
|
|
$this->articles = $articles; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* {@inheritdoc} |
91
|
|
|
*/ |
92
|
21 |
|
public function getId() |
93
|
|
|
{ |
94
|
21 |
|
return parent::getId(); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* {@inheritdoc} |
99
|
|
|
*/ |
100
|
|
|
public function getRouteName() |
101
|
|
|
{ |
102
|
|
|
return $this->getName(); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* {@inheritdoc} |
107
|
|
|
*/ |
108
|
|
|
public function isRoot(): bool |
109
|
|
|
{ |
110
|
|
|
return null === $this->parent; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* {@inheritdoc} |
115
|
|
|
*/ |
116
|
|
|
public function getRoot(): RouteInterface |
117
|
|
|
{ |
118
|
|
|
return $this->root; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* {@inheritdoc} |
123
|
|
|
*/ |
124
|
|
|
public function getParent() |
125
|
|
|
{ |
126
|
|
|
return $this->parent; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* {@inheritdoc} |
131
|
|
|
*/ |
132
|
|
|
public function setParent(RouteInterface $parent = null) |
133
|
|
|
{ |
134
|
|
|
$this->parent = $parent; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @return Collection|RouteInterface[] |
139
|
|
|
*/ |
140
|
|
|
public function getChildren() |
141
|
|
|
{ |
142
|
|
|
return $this->children; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* {@inheritdoc} |
147
|
|
|
*/ |
148
|
|
|
public function hasChild(RouteInterface $route): bool |
149
|
|
|
{ |
150
|
|
|
return $this->children->contains($route); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* {@inheritdoc} |
155
|
|
|
*/ |
156
|
|
|
public function addChild(RouteInterface $route) |
157
|
|
|
{ |
158
|
|
|
if (!$this->hasChild($route)) { |
159
|
|
|
$route->setParent($this); |
160
|
|
|
$this->children->add($route); |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* {@inheritdoc} |
166
|
|
|
*/ |
167
|
|
|
public function removeChild(RouteInterface $route) |
168
|
|
|
{ |
169
|
|
|
if ($this->hasChild($route)) { |
170
|
|
|
$route->setParent(null); |
171
|
|
|
$this->children->removeElement($route); |
172
|
|
|
} |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* {@inheritdoc} |
177
|
|
|
*/ |
178
|
|
|
public function getLeft(): int |
179
|
|
|
{ |
180
|
|
|
return $this->lft; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* {@inheritdoc} |
185
|
|
|
*/ |
186
|
|
|
public function setLeft(int $left) |
187
|
|
|
{ |
188
|
|
|
$this->lft = $left; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* {@inheritdoc} |
193
|
|
|
*/ |
194
|
|
|
public function getRight(): int |
195
|
|
|
{ |
196
|
|
|
return $this->rgt; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @param int $right |
201
|
|
|
*/ |
202
|
|
|
public function setRight(int $right) |
203
|
|
|
{ |
204
|
|
|
$this->rgt = $right; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* {@inheritdoc} |
209
|
|
|
*/ |
210
|
|
|
public function getLevel(): int |
211
|
|
|
{ |
212
|
|
|
return $this->level; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* {@inheritdoc} |
217
|
|
|
*/ |
218
|
|
|
public function setLevel(int $level) |
219
|
|
|
{ |
220
|
|
|
$this->level = $level; |
221
|
|
|
} |
222
|
|
|
} |
223
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.