Completed
Push — master ( c3ce72...f2565d )
by Paweł
20s
created

Route::unserialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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