Completed
Push — master ( fc2d7f...dda5b7 )
by Eric
03:12
created

PropertyMetadata::setExposed()   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 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\Mapping;
13
14
/**
15
 * @author GeLo <[email protected]>
16
 */
17
class PropertyMetadata implements PropertyMetadataInterface
18
{
19
    /**
20
     * @var string
21
     */
22
    private $name;
23
24
    /**
25
     * @var string
26
     */
27
    private $alias;
28
29
    /**
30
     * @var TypeMetadataInterface|null
31
     */
32
    private $type;
33
34
    /**
35
     * @var bool|null
36
     */
37
    private $exposed;
38
39
    /**
40
     * @var bool|null
41
     */
42
    private $excluded;
43
44
    /**
45
     * @var string|null
46
     */
47
    private $since;
48
49
    /**
50
     * @var string|null
51
     */
52
    private $until;
53
54
    /**
55
     * @var int|null
56
     */
57
    private $maxDepth;
58
59
    /**
60
     * @var string[]
61
     */
62
    private $groups = [];
63
64
    /**
65
     * @param string $name
66
     */
67
    public function __construct($name)
68
    {
69
        $this->setName($name);
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function getName()
76
    {
77
        return $this->name;
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83
    public function setName($name)
84
    {
85
        $this->name = $name;
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91
    public function hasAlias()
92
    {
93
        return $this->alias !== null;
94
    }
95
96
    /**
97
     * {@inheritdoc}
98
     */
99
    public function getAlias()
100
    {
101
        return $this->alias;
102
    }
103
104
    /**
105
     * {@inheritdoc}
106
     */
107
    public function setAlias($alias)
108
    {
109
        $this->alias = $alias;
110
    }
111
112
    /**
113
     * {@inheritdoc}
114
     */
115
    public function hasType()
116
    {
117
        return $this->type !== null;
118
    }
119
120
    /**
121
     * {@inheritdoc}
122
     */
123
    public function getType()
124
    {
125
        return $this->type;
126
    }
127
128
    /**
129
     * {@inheritdoc}
130
     */
131
    public function setType(TypeMetadataInterface $type = null)
132
    {
133
        $this->type = $type;
134
    }
135
136
    /**
137
     * {@inheritdoc}
138
     */
139
    public function isExposed()
140
    {
141
        return $this->exposed;
142
    }
143
144
    /**
145
     * {@inheritdoc}
146
     */
147
    public function setExposed($exposed)
148
    {
149
        $this->exposed = $exposed;
150
    }
151
152
    /**
153
     * {@inheritdoc}
154
     */
155
    public function isExcluded()
156
    {
157
        return $this->excluded;
158
    }
159
160
    /**
161
     * {@inheritdoc}
162
     */
163
    public function setExcluded($excluded)
164
    {
165
        $this->excluded = $excluded;
166
    }
167
168
    /**
169
     * {@inheritdoc}
170
     */
171
    public function hasSinceVersion()
172
    {
173
        return $this->since !== null;
174
    }
175
176
    /**
177
     * {@inheritdoc}
178
     */
179
    public function getSinceVersion()
180
    {
181
        return $this->since;
182
    }
183
184
    /**
185
     * {@inheritdoc}
186
     */
187
    public function setSinceVersion($since)
188
    {
189
        $this->since = $since;
190
    }
191
192
    /**
193
     * {@inheritdoc}
194
     */
195
    public function hasUntilVersion()
196
    {
197
        return $this->until !== null;
198
    }
199
200
    /**
201
     * {@inheritdoc}
202
     */
203
    public function getUntilVersion()
204
    {
205
        return $this->until;
206
    }
207
208
    /**
209
     * {@inheritdoc}
210
     */
211
    public function setUntilVersion($until)
212
    {
213
        $this->until = $until;
214
    }
215
216
    /**
217
     * {@inheritdoc}
218
     */
219
    public function hasMaxDepth()
220
    {
221
        return $this->maxDepth !== null;
222
    }
223
224
    /**
225
     * {@inheritdoc}
226
     */
227
    public function getMaxDepth()
228
    {
229
        return $this->maxDepth;
230
    }
231
232
    /**
233
     * {@inheritdoc}
234
     */
235
    public function setMaxDepth($maxDepth)
236
    {
237
        $this->maxDepth = $maxDepth;
238
    }
239
240
    /**
241
     * {@inheritdoc}
242
     */
243
    public function hasGroups()
244
    {
245
        return !empty($this->groups);
246
    }
247
248
    /**
249
     * {@inheritdoc}
250
     */
251
    public function getGroups()
252
    {
253
        return array_values($this->groups);
254
    }
255
256
    /**
257
     * {@inheritdoc}
258
     */
259
    public function setGroups(array $groups)
260
    {
261
        $this->groups = [];
262
        $this->addGroups($groups);
263
    }
264
265
    /**
266
     * {@inheritdoc}
267
     */
268
    public function addGroups(array $groups)
269
    {
270
        foreach ($groups as $group) {
271
            $this->addGroup($group);
272
        }
273
    }
274
275
    /**
276
     * {@inheritdoc}
277
     */
278
    public function hasGroup($group)
279
    {
280
        return in_array($group, $this->groups, true);
281
    }
282
283
    /**
284
     * {@inheritdoc}
285
     */
286
    public function addGroup($group)
287
    {
288
        if (!$this->hasGroup($group)) {
289
            $this->groups[] = $group;
290
        }
291
    }
292
293
    /**
294
     * {@inheritdoc}
295
     */
296
    public function removeGroup($group)
297
    {
298
        unset($this->groups[array_search($group, $this->groups, true)]);
299
    }
300
301
    /**
302
     * {@inheritdoc}
303
     */
304
    public function merge(PropertyMetadataInterface $propertyMetadata)
305
    {
306
        if (!$this->hasType() && $propertyMetadata->hasType()) {
307
            $this->setType($propertyMetadata->getType());
308
        }
309
310
        if (!$this->hasMaxDepth() && $propertyMetadata->hasMaxDepth()) {
311
            $this->setMaxDepth($propertyMetadata->getMaxDepth());
312
        }
313
314
        foreach ($propertyMetadata->getGroups() as $group) {
315
            $this->addGroup($group);
316
        }
317
    }
318
}
319