Completed
Push — master ( a7a790...5c4323 )
by Eric
03:39
created

Context::setNavigator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
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\Exclusion\ExclusionStrategy;
15
use Ivory\Serializer\Exclusion\ExclusionStrategyInterface;
16
use Ivory\Serializer\Mapping\MetadataInterface;
17
use Ivory\Serializer\Naming\IdenticalNamingStrategy;
18
use Ivory\Serializer\Naming\NamingStrategyInterface;
19
use Ivory\Serializer\Navigator\NavigatorInterface;
20
use Ivory\Serializer\Visitor\VisitorInterface;
21
22
/**
23
 * @author GeLo <[email protected]>
24
 */
25
class Context implements ContextInterface
26
{
27
    /**
28
     * @var NavigatorInterface
29
     */
30
    private $navigator;
31
32
    /**
33
     * @var VisitorInterface
34
     */
35
    private $visitor;
36
37
    /**
38
     * @var int
39
     */
40
    private $direction;
41
42
    /**
43
     * @var bool
44
     */
45
    private $ignoreNull = false;
46
47
    /**
48
     * @var ExclusionStrategyInterface
49
     */
50
    private $exclusionStrategy;
51
52
    /**
53
     * @var NamingStrategyInterface
54
     */
55
    private $namingStrategy;
56
57
    /**
58
     * @var mixed[]
59
     */
60
    private $dataStack;
61
62
    /**
63
     * @var MetadataInterface[]
64
     */
65
    private $metadataStack;
66
67
    /**
68
     * @param ExclusionStrategyInterface|null $exclusionStrategy
69
     * @param NamingStrategyInterface|null    $namingStrategy
70
     */
71 594
    public function __construct(
72
        ExclusionStrategyInterface $exclusionStrategy = null,
73
        NamingStrategyInterface $namingStrategy = null
74
    ) {
75 594
        $this->exclusionStrategy = $exclusionStrategy ?: new ExclusionStrategy();
76 594
        $this->namingStrategy = $namingStrategy ?: new IdenticalNamingStrategy();
77 594
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82 738
    public function initialize(NavigatorInterface $navigator, VisitorInterface $visitor, $direction)
83
    {
84 492
        $this
85 738
            ->setNavigator($navigator)
86 738
            ->setVisitor($visitor)
87 738
            ->setDirection($direction)
88 738
            ->setDataStack([])
89 738
            ->setMetadataStack([]);
90 738
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95 738
    public function getNavigator()
96
    {
97 738
        return $this->navigator;
98
    }
99
100
    /**
101
     * {@inheritdoc}
102
     */
103 738
    public function setNavigator(NavigatorInterface $navigator)
104
    {
105 738
        $this->navigator = $navigator;
106
107 738
        return $this;
108
    }
109
110
    /**
111
     * {@inheritdoc}
112
     */
113 738
    public function getVisitor()
114
    {
115 738
        return $this->visitor;
116
    }
117
118
    /**
119
     * {@inheritdoc}
120
     */
121 738
    public function setVisitor(VisitorInterface $visitor)
122
    {
123 738
        $this->visitor = $visitor;
124
125 738
        return $this;
126
    }
127
128
    /**
129
     * {@inheritdoc}
130
     */
131 72
    public function getDirection()
132
    {
133 72
        return $this->direction;
134
    }
135
136
    /**
137
     * {@inheritdoc}
138
     */
139 738
    public function setDirection($direction)
140
    {
141 738
        $this->direction = $direction;
142
143 738
        return $this;
144
    }
145
146
    /**
147
     * {@inheritdoc}
148
     */
149 147
    public function isNullIgnored()
150
    {
151 147
        return $this->ignoreNull;
152
    }
153
154
    /**
155
     * {@inheritdoc}
156
     */
157
    public function setIgnoreNull($ignoreNull)
158
    {
159
        $this->ignoreNull = $ignoreNull;
160
161
        return $this;
162
    }
163
164
    /**
165
     * {@inheritdoc}
166
     */
167 600
    public function getExclusionStrategy()
168
    {
169 600
        return $this->exclusionStrategy;
170
    }
171
172
    /**
173
     * {@inheritdoc}
174
     */
175
    public function setExclusionStrategy(ExclusionStrategyInterface $exclusionStrategy)
176
    {
177
        $this->exclusionStrategy = $exclusionStrategy;
178
179
        return $this;
180
    }
181
182
    /**
183
     * {@inheritdoc}
184
     */
185 576
    public function getNamingStrategy()
186
    {
187 576
        return $this->namingStrategy;
188
    }
189
190
    /**
191
     * {@inheritdoc}
192
     */
193
    public function setNamingStrategy(NamingStrategyInterface $namingStrategy)
194
    {
195
        $this->namingStrategy = $namingStrategy;
196
197
        return $this;
198
    }
199
200
    /**
201
     * {@inheritdoc}
202
     */
203 18
    public function getDataStack()
204
    {
205 18
        return $this->dataStack;
206
    }
207
208
    /**
209
     * {@inheritdoc}
210
     */
211 738
    public function setDataStack(array $dataStack)
212
    {
213 738
        $this->dataStack = $dataStack;
214
215 738
        return $this;
216
    }
217
218
    /**
219
     * {@inheritdoc}
220
     */
221 18
    public function getMetadataStack()
222
    {
223 18
        return $this->metadataStack;
224
    }
225
226
    /**
227
     * {@inheritdoc}
228
     */
229 738
    public function setMetadataStack(array $metadataStack)
230
    {
231 738
        $this->metadataStack = $metadataStack;
232
233 738
        return $this;
234
    }
235
236
    /**
237
     * {@inheritdoc}
238
     */
239 600
    public function enterScope($data, MetadataInterface $metadata)
240
    {
241 600
        $this->dataStack[] = $data;
242 600
        $this->metadataStack[] = $metadata;
243 600
    }
244
245
    /**
246
     * {@inheritdoc}
247
     */
248 600
    public function leaveScope()
249
    {
250 600
        array_pop($this->dataStack);
251 600
        array_pop($this->metadataStack);
252 600
    }
253
}
254