Completed
Push — master ( 43d45a...5355f5 )
by Eric
02:45
created

Context::hasMaxDepthEnabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Ivory Serializer package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\Serializer\Context;
13
14
use Ivory\Serializer\Navigator\NavigatorInterface;
15
use Ivory\Serializer\Visitor\VisitorInterface;
16
17
/**
18
 * @author GeLo <[email protected]>
19
 */
20
class Context implements ContextInterface
21
{
22
    /**
23
     * @var NavigatorInterface
24
     */
25
    private $navigator;
26
27
    /**
28
     * @var VisitorInterface
29
     */
30
    private $visitor;
31
32
    /**
33
     * @var int
34
     */
35
    private $direction;
36
37
    /**
38
     * @var bool
39
     */
40
    private $maxDepth = false;
41
42
    /**
43
     * @var string|null
44
     */
45
    private $version;
46
47
    /**
48
     * @var string[]
49
     */
50
    private $groups = [];
51
52
    /**
53
     * @var \SplStack
54
     */
55
    private $dataStack;
56
57
    /**
58
     * @var \SplStack
59
     */
60
    private $metadataStack;
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function __construct()
66
    {
67
        $this->dataStack = new \SplStack();
68
        $this->metadataStack = new \SplStack();
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function getNavigator()
75
    {
76
        return $this->navigator;
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82
    public function setNavigator(NavigatorInterface $navigator)
83
    {
84
        $this->navigator = $navigator;
85
86
        return $this;
87
    }
88
89
    /**
90
     * {@inheritdoc}
91
     */
92
    public function getVisitor()
93
    {
94
        return $this->visitor;
95
    }
96
97
    /**
98
     * {@inheritdoc}
99
     */
100
    public function setVisitor(VisitorInterface $visitor)
101
    {
102
        $this->visitor = $visitor;
103
104
        return $this;
105
    }
106
107
    /**
108
     * {@inheritdoc}
109
     */
110
    public function getDirection()
111
    {
112
        return $this->direction;
113
    }
114
115
    /**
116
     * {@inheritdoc}
117
     */
118
    public function setDirection($direction)
119
    {
120
        $this->direction = $direction;
121
122
        return $this;
123
    }
124
125
    /**
126
     * @return bool
127
     */
128
    public function hasMaxDepthEnabled()
129
    {
130
        return $this->maxDepth;
131
    }
132
133
    /**
134
     * {@inheritdoc}
135
     */
136
    public function enableMaxDepth($enable = true)
137
    {
138
        $this->maxDepth = $enable;
139
140
        return $this;
141
    }
142
143
    /**
144
     * {@inheritdoc}
145
     */
146
    public function hasVersion()
147
    {
148
        return $this->version !== null;
149
    }
150
151
    /**
152
     * {@inheritdoc}
153
     */
154
    public function getVersion()
155
    {
156
        return $this->version;
157
    }
158
159
    /**
160
     * {@inheritdoc}
161
     */
162
    public function setVersion($version)
163
    {
164
        $this->version = $version;
165
166
        return $this;
167
    }
168
169
    /**
170
     * {@inheritdoc}
171
     */
172
    public function hasGroups()
173
    {
174
        return !empty($this->groups);
175
    }
176
177
    /**
178
     * {@inheritdoc}
179
     */
180
    public function getGroups()
181
    {
182
        return array_values($this->groups);
183
    }
184
185
    /**
186
     * {@inheritdoc}
187
     */
188
    public function setGroups(array $groups)
189
    {
190
        $this->groups = [];
191
        $this->addGroups($groups);
192
193
        return $this;
194
    }
195
196
    /**
197
     * {@inheritdoc}
198
     */
199
    public function addGroups(array $groups)
200
    {
201
        foreach ($groups as $group) {
202
            $this->addGroup($group);
203
        }
204
205
        return $this;
206
    }
207
208
    /**
209
     * {@inheritdoc}
210
     */
211
    public function hasGroup($group)
212
    {
213
        return in_array($group, $this->groups, true);
214
    }
215
216
    /**
217
     * {@inheritdoc}
218
     */
219
    public function addGroup($group)
220
    {
221
        if (!$this->hasGroup($group)) {
222
            $this->groups[] = $group;
223
        }
224
225
        return $this;
226
    }
227
228
    /**
229
     * {@inheritdoc}
230
     */
231
    public function removeGroup($group)
232
    {
233
        unset($this->groups[array_search($group, $this->groups, true)]);
234
235
        return $this;
236
    }
237
238
    /**
239
     * {@inheritdoc}
240
     */
241
    public function getDataStack()
242
    {
243
        return $this->dataStack;
244
    }
245
246
    /**
247
     * {@inheritdoc}
248
     */
249
    public function getMetadataStack()
250
    {
251
        return $this->metadataStack;
252
    }
253
}
254