Completed
Push — master ( ddba2d...d7dfff )
by Eric
14:58
created

Context::leaveScope()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
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 \SplStack
44
     */
45
    private $dataStack;
46
47
    /**
48
     * @var \SplStack
49
     */
50
    private $metadataStack;
51
52
    /**
53
     * @var ExclusionStrategyInterface
54
     */
55
    private $exclusionStrategy;
56
57
    /**
58
     * @var NamingStrategyInterface
59
     */
60
    private $namingStrategy;
61
62
    /**
63
     * @param ExclusionStrategyInterface|null $exclusionStrategy
64
     * @param NamingStrategyInterface|null    $namingStrategy
65
     */
66 468
    public function __construct(
67
        ExclusionStrategyInterface $exclusionStrategy = null,
68
        NamingStrategyInterface $namingStrategy = null
69
    ) {
70 468
        $this->exclusionStrategy = $exclusionStrategy ?: new ExclusionStrategy();
71 468
        $this->namingStrategy = $namingStrategy ?: new IdenticalNamingStrategy();
72 468
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77 549
    public function getNavigator()
78
    {
79 549
        return $this->navigator;
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85 549
    public function setNavigator(NavigatorInterface $navigator)
86
    {
87 549
        $this->navigator = $navigator;
88
89 549
        return $this;
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95 549
    public function getVisitor()
96
    {
97 549
        return $this->visitor;
98
    }
99
100
    /**
101
     * {@inheritdoc}
102
     */
103 549
    public function setVisitor(VisitorInterface $visitor)
104
    {
105 549
        $this->visitor = $visitor;
106
107 549
        return $this;
108
    }
109
110
    /**
111
     * {@inheritdoc}
112
     */
113 72
    public function getDirection()
114
    {
115 72
        return $this->direction;
116
    }
117
118
    /**
119
     * {@inheritdoc}
120
     */
121 549
    public function setDirection($direction)
122
    {
123 549
        $this->direction = $direction;
124
125 549
        return $this;
126
    }
127
128
    /**
129
     * {@inheritdoc}
130
     */
131 411
    public function getExclusionStrategy()
132
    {
133 411
        return $this->exclusionStrategy;
134
    }
135
136
    /**
137
     * {@inheritdoc}
138
     */
139
    public function setExclusionStrategy(ExclusionStrategyInterface $exclusionStrategy)
140
    {
141
        $this->exclusionStrategy = $exclusionStrategy;
142
143
        return $this;
144
    }
145
146
    /**
147
     * {@inheritdoc}
148
     */
149 387
    public function getNamingStrategy()
150
    {
151 387
        return $this->namingStrategy;
152
    }
153
154
    /**
155
     * {@inheritdoc}
156
     */
157
    public function setNamingStrategy(NamingStrategyInterface $namingStrategy)
158
    {
159
        $this->namingStrategy = $namingStrategy;
160
161
        return $this;
162
    }
163
164
    /**
165
     * {@inheritdoc}
166
     */
167 549
    public function getDataStack()
168
    {
169 549
        return $this->dataStack;
170
    }
171
172
    /**
173
     * {@inheritdoc}
174
     */
175 549
    public function setDataStack(\SplStack $dataStack)
176
    {
177 549
        $this->dataStack = $dataStack;
178
179 549
        return $this;
180
    }
181
182
    /**
183
     * {@inheritdoc}
184
     */
185 549
    public function getMetadataStack()
186
    {
187 549
        return $this->metadataStack;
188
    }
189
190
    /**
191
     * {@inheritdoc}
192
     */
193 549
    public function setMetadataStack(\SplStack $metadataStack)
194
    {
195 549
        $this->metadataStack = $metadataStack;
196
197 549
        return $this;
198
    }
199
200
    /**
201
     * {@inheritdoc}
202
     */
203 411
    public function enterScope($data, MetadataInterface $metadata)
204
    {
205 411
        $this->dataStack->push($data);
206 411
        $this->metadataStack->push($metadata);
207 411
    }
208
209
    /**
210
     * {@inheritdoc}
211
     */
212 411
    public function leaveScope()
213
    {
214 411
        $this->dataStack->pop();
215 411
        $this->metadataStack->pop();
216 411
    }
217
}
218