Completed
Push — master ( 36d725...742cf9 )
by Paweł
20s queued 10s
created

Route::getRight()   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 0
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, ArticlesAwareTrait;
24
25
    /**
26
     * @var int
27
     */
28
    protected $id;
29
30
    /**
31
     * @var RouteInterface
32
     */
33
    protected $parent;
34
35
    /**
36
     * @var Collection|RouteInterface[]
37
     */
38
    protected $children;
39
40
    /**
41
     * @var int
42
     */
43
    protected $lft;
44
45
    /**
46
     * @var int
47
     */
48
    protected $rgt;
49
50
    /**
51
     * @var int
52
     */
53
    protected $level;
54
55
    /**
56
     * Route constructor.
57
     */
58
    public function __construct()
59
    {
60
        $this->articles = new ArrayCollection();
61
        $this->children = new ArrayCollection();
62
63
        parent::__construct();
64
    }
65 104
66
    /**
67 104
     * {@inheritdoc}
68 104
     */
69
    public function getId()
70 104
    {
71 104
        return parent::getId();
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function getRouteName()
78
    {
79
        return $this->getName();
80
    }
81
82
    /**
83
     * @param ArticleInterface $article
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
    /**
188
     * @param int $right
189
     */
190
    public function setRight(int $right)
191
    {
192
        $this->rgt = $right;
193
    }
194
195
    /**
196
     * {@inheritdoc}
197
     */
198
    public function getLevel(): int
199
    {
200
        return $this->level;
201
    }
202
203
    /**
204
     * {@inheritdoc}
205
     */
206
    public function setLevel(int $level)
207
    {
208
        $this->level = $level;
209
    }
210
211
    /**
212
     * {@inheritdoc}
213
     */
214
    public function getParentId()
215
    {
216
        if (null !== $this->parent) {
217
            return (int) $this->parent->getId();
218
        }
219
    }
220
221
    public function __toString()
222
    {
223
        return $this->getName();
224
    }
225
}
226