Completed
Push — master ( a682ba...4851b3 )
by Paweł
40:50
created

Route::removeChild()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 6
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher Content Bundle.
7
 *
8
 * Copyright 2016 Sourcefabric z.ú. and contributors.
9
 *
10
 * For the full copyright and license information, please see the
11
 * AUTHORS and LICENSE files distributed with this source code.
12
 *
13
 * @copyright 2016 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\ContentBundle\Doctrine\ORM;
18
19
use Doctrine\Common\Collections\ArrayCollection;
20
use Doctrine\Common\Collections\Collection;
21
use SWP\Bundle\ContentBundle\Model\RouteInterface;
22
use SWP\Bundle\ContentBundle\Model\RouteTrait;
23
use SWP\Component\MultiTenancy\Model\TenantAwareInterface;
24
use SWP\Component\MultiTenancy\Model\TenantAwareTrait;
25
use Symfony\Cmf\Bundle\RoutingBundle\Model\Route as BaseRoute;
26
use SWP\Component\Storage\Model\PersistableInterface;
27
28
class Route extends BaseRoute implements
29
    PersistableInterface,
30
    RouteInterface,
31
    TenantAwareInterface
32
{
33
    use RouteTrait, TenantAwareTrait;
34
35
    /**
36
     * @var int
37
     */
38
    protected $id;
39
40
    /**
41
     * @var Collection
42
     */
43
    protected $articles;
44
45
    /**
46
     * @var RouteInterface
47
     */
48
    protected $root;
49
50
    /**
51
     * @var RouteInterface
52
     */
53
    protected $parent;
54
55
    /**
56
     * @var Collection|RouteInterface[]
57
     */
58
    protected $children;
59
60
    /**
61
     * @var int
62
     */
63
    protected $lft;
64
65
    /**
66
     * @var int
67
     */
68
    protected $rgt;
69
70
    /**
71
     * @var int
72
     */
73
    protected $level;
74
75 103
    public function __construct()
76
    {
77 103
        $this->articles = new ArrayCollection();
78 103
        $this->children = new ArrayCollection();
79
80 103
        parent::__construct();
81 103
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86
    public function getArticles()
87
    {
88
        return $this->articles;
89
    }
90
91
    /**
92
     * {@inheritdoc}
93
     */
94
    public function setArticles($articles)
95
    {
96
        $this->articles = $articles;
97
    }
98
99
    /**
100
     * {@inheritdoc}
101
     */
102 46
    public function getId()
103
    {
104 46
        return parent::getId();
105
    }
106
107
    /**
108
     * {@inheritdoc}
109
     */
110 12
    public function getRouteName()
111
    {
112 12
        return $this->getName();
113
    }
114
115
    /**
116
     * {@inheritdoc}
117
     */
118
    public function isRoot(): bool
119
    {
120
        return null === $this->parent;
121
    }
122
123
    /**
124
     * {@inheritdoc}
125
     */
126
    public function getRoot(): RouteInterface
127
    {
128
        return $this->root;
129
    }
130
131
    /**
132
     * {@inheritdoc}
133
     */
134 50
    public function getParent()
135
    {
136 50
        return $this->parent;
137
    }
138
139
    /**
140
     * {@inheritdoc}
141
     */
142 2
    public function setParent(RouteInterface $parent = null)
143
    {
144 2
        $this->parent = $parent;
145 2
    }
146
147
    /**
148
     * @return Collection|RouteInterface[]
149
     */
150
    public function getChildren()
151
    {
152
        return $this->children;
153
    }
154
155
    /**
156
     * {@inheritdoc}
157
     */
158
    public function hasChild(RouteInterface $route): bool
159
    {
160
        return $this->children->contains($route);
161
    }
162
163
    /**
164
     * {@inheritdoc}
165
     */
166
    public function addChild(RouteInterface $route)
167
    {
168
        if (!$this->hasChild($route)) {
169
            $route->setParent($this);
170
            $this->children->add($route);
171
        }
172
    }
173
174
    /**
175
     * {@inheritdoc}
176
     */
177
    public function removeChild(RouteInterface $route)
178
    {
179
        if ($this->hasChild($route)) {
180
            $route->setParent(null);
181
            $this->children->removeElement($route);
182
        }
183
    }
184
185
    /**
186
     * {@inheritdoc}
187
     */
188
    public function getLeft(): int
189
    {
190
        return $this->lft;
191
    }
192
193
    /**
194
     * {@inheritdoc}
195
     */
196
    public function setLeft(int $left)
197
    {
198
        $this->lft = $left;
199
    }
200
201
    /**
202
     * {@inheritdoc}
203
     */
204
    public function getRight(): int
205
    {
206
        return $this->rgt;
207
    }
208
209
    /**
210
     * @param int $right
211
     */
212
    public function setRight(int $right)
213
    {
214
        $this->rgt = $right;
215
    }
216
217
    /**
218
     * {@inheritdoc}
219
     */
220
    public function getLevel(): int
221
    {
222
        return $this->level;
223
    }
224
225
    /**
226
     * {@inheritdoc}
227
     */
228
    public function setLevel(int $level)
229
    {
230
        $this->level = $level;
231
    }
232
}
233