Completed
Push — master ( 7a069b...4da1f4 )
by Paweł
11s
created

Route::getParentId()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 2
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 0
crap 6
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, ArticlesAwareTrait;
24
25
    /**
26
     * @var int
27
     */
28
    protected $id;
29
30
    /**
31
     * @var RouteInterface
32
     */
33
    protected $root;
34
35
    /**
36
     * @var RouteInterface
37
     */
38
    protected $parent;
39
40
    /**
41
     * @var Collection|RouteInterface[]
42
     */
43
    protected $children;
44
45
    /**
46
     * @var int
47
     */
48
    protected $lft;
49
50
    /**
51
     * @var int
52
     */
53
    protected $rgt;
54
55
    /**
56
     * @var int
57
     */
58
    protected $level;
59
60
    /**
61
     * Route constructor.
62
     */
63
    public function __construct()
64
    {
65 104
        $this->articles = new ArrayCollection();
66
        $this->children = new ArrayCollection();
67 104
68 104
        parent::__construct();
69
    }
70 104
71 104
    /**
72
     * {@inheritdoc}
73
     */
74
    public function getId()
75
    {
76
        return parent::getId();
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82
    public function getRouteName()
83
    {
84
        return $this->getName();
85
    }
86
87
    /**
88
     * @param ArticleInterface $article
89
     */
90
    public function addArticle(ArticleInterface $article): void
91
    {
92 30
        if (!$this->articles->contains($article)) {
93
            $this->articles->add($article);
94 30
            $article->setRoute($this);
95
        }
96
    }
97
98
    /**
99
     * {@inheritdoc}
100
     */
101
    public function isRoot(): bool
102
    {
103
        return null === $this->parent;
104
    }
105
106
    /**
107
     * {@inheritdoc}
108
     */
109
    public function getRoot(): RouteInterface
110
    {
111
        return $this->root;
112
    }
113
114
    /**
115
     * {@inheritdoc}
116
     */
117
    public function getParent()
118
    {
119
        return $this->parent;
120
    }
121
122
    /**
123
     * {@inheritdoc}
124
     */
125
    public function setParent(RouteInterface $parent = null)
126
    {
127
        $this->parent = $parent;
128
    }
129
130
    /**
131
     * @return Collection|RouteInterface[]
132
     */
133
    public function getChildren()
134
    {
135
        return $this->children;
136
    }
137
138
    /**
139
     * {@inheritdoc}
140
     */
141
    public function hasChild(RouteInterface $route): bool
142
    {
143
        return $this->children->contains($route);
144
    }
145
146
    /**
147
     * {@inheritdoc}
148
     */
149
    public function addChild(RouteInterface $route)
150
    {
151
        if (!$this->hasChild($route)) {
152
            $route->setParent($this);
153
            $this->children->add($route);
154
        }
155
    }
156
157
    /**
158
     * {@inheritdoc}
159
     */
160
    public function removeChild(RouteInterface $route)
161
    {
162
        if ($this->hasChild($route)) {
163
            $route->setParent(null);
164
            $this->children->removeElement($route);
165
        }
166
    }
167
168
    /**
169
     * {@inheritdoc}
170
     */
171
    public function getLeft(): int
172
    {
173
        return $this->lft;
174
    }
175
176
    /**
177
     * {@inheritdoc}
178
     */
179
    public function setLeft(int $left)
180
    {
181
        $this->lft = $left;
182
    }
183
184
    /**
185
     * {@inheritdoc}
186
     */
187
    public function getRight(): int
188
    {
189
        return $this->rgt;
190
    }
191
192
    /**
193
     * @param int $right
194
     */
195
    public function setRight(int $right)
196
    {
197
        $this->rgt = $right;
198
    }
199
200
    /**
201
     * {@inheritdoc}
202
     */
203
    public function getLevel(): int
204
    {
205
        return $this->level;
206
    }
207
208
    /**
209
     * {@inheritdoc}
210
     */
211
    public function setLevel(int $level)
212
    {
213
        $this->level = $level;
214
    }
215
216
    /**
217
     * {@inheritdoc}
218
     */
219
    public function getParentId()
220
    {
221
        if (null !== $this->parent) {
222
            return (int) $this->parent->getId();
223
        }
224
    }
225
226
    /**
227
     * {@inheritdoc}
228
     */
229
    public function getRootId()
230
    {
231
        if (null !== $this->root) {
232
            return (int) $this->root->getId();
233
        }
234
    }
235
}
236