Completed
Pull Request — master (#11)
by Eric
21:21 queued 18:00
created

PropertyMetadata::setMutator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
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\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
36
     */
37
    private $readable = true;
38
39
    /**
40
     * @var bool
41
     */
42
    private $writable = true;
43
44
    /**
45
     * @var string|null
46
     */
47
    private $accessor;
48
49
    /**
50
     * @var string|null
51
     */
52
    private $mutator;
53
54
    /**
55
     * @var string|null
56
     */
57
    private $since;
58
59
    /**
60
     * @var string|null
61
     */
62
    private $until;
63
64
    /**
65
     * @var int|null
66
     */
67
    private $maxDepth;
68
69
    /**
70
     * @var string[]
71
     */
72
    private $groups = [];
73
74
    /**
75
     * @var bool
76
     */
77
    private $xmlAttribute = false;
78
79
    /**
80
     * @var bool
81
     */
82
    private $xmlValue = false;
83
84
    /**
85
     * @param string $name
86
     */
87 1323
    public function __construct($name)
88
    {
89 1323
        $this->setName($name);
90 1323
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95 1146
    public function getName()
96
    {
97 1146
        return $this->name;
98
    }
99
100
    /**
101
     * {@inheritdoc}
102
     */
103 1323
    public function setName($name)
104
    {
105 1323
        $this->name = $name;
106 1323
    }
107
108
    /**
109
     * {@inheritdoc}
110
     */
111 1101
    public function hasAlias()
112
    {
113 1101
        return $this->alias !== null;
114
    }
115
116
    /**
117
     * {@inheritdoc}
118
     */
119 381
    public function getAlias()
120
    {
121 381
        return $this->alias;
122
    }
123
124
    /**
125
     * {@inheritdoc}
126
     */
127 114
    public function setAlias($alias)
128
    {
129 114
        $this->alias = $alias;
130 114
    }
131
132
    /**
133
     * {@inheritdoc}
134
     */
135 285
    public function hasType()
136
    {
137 285
        return $this->type !== null;
138
    }
139
140
    /**
141
     * {@inheritdoc}
142
     */
143 867
    public function getType()
144
    {
145 867
        return $this->type;
146
    }
147
148
    /**
149
     * {@inheritdoc}
150
     */
151 336
    public function setType(TypeMetadataInterface $type = null)
152
    {
153 336
        $this->type = $type;
154 336
    }
155
156
    /**
157
     * {@inheritdoc}
158
     */
159 789
    public function isReadable()
160
    {
161 789
        return $this->readable;
162
    }
163
164
    /**
165
     * {@inheritdoc}
166
     */
167 1266
    public function setReadable($readable)
168
    {
169 1266
        $this->readable = $readable;
170 1266
    }
171
172
    /**
173
     * {@inheritdoc}
174
     */
175 597
    public function isWritable()
176
    {
177 597
        return $this->writable;
178
    }
179
180
    /**
181
     * {@inheritdoc}
182
     */
183 1263
    public function setWritable($writable)
184
    {
185 1263
        $this->writable = $writable;
186 1263
    }
187
188
    /**
189
     * {@inheritdoc}
190
     */
191 789
    public function hasAccessor()
192
    {
193 789
        return $this->accessor !== null;
194
    }
195
196
    /**
197
     * {@inheritdoc}
198
     */
199 297
    public function getAccessor()
200
    {
201 297
        return $this->accessor;
202
    }
203
204
    /**
205
     * {@inheritdoc}
206
     */
207 42
    public function setAccessor($accessor)
208
    {
209 42
        $this->accessor = $accessor;
210 42
    }
211
212
    /**
213
     * {@inheritdoc}
214
     */
215 537
    public function hasMutator()
216
    {
217 537
        return $this->mutator !== null;
218
    }
219
220
    /**
221
     * {@inheritdoc}
222
     */
223 297
    public function getMutator()
224
    {
225 297
        return $this->mutator;
226
    }
227
228
    /**
229
     * {@inheritdoc}
230
     */
231 42
    public function setMutator($mutator)
232
    {
233 42
        $this->mutator = $mutator;
234 42
    }
235
236
    /**
237
     * {@inheritdoc}
238
     */
239 333
    public function hasSinceVersion()
240
    {
241 333
        return $this->since !== null;
242
    }
243
244
    /**
245
     * {@inheritdoc}
246
     */
247 333
    public function getSinceVersion()
248
    {
249 333
        return $this->since;
250
    }
251
252
    /**
253
     * {@inheritdoc}
254
     */
255 90
    public function setSinceVersion($since)
256
    {
257 90
        $this->since = $since;
258 90
    }
259
260
    /**
261
     * {@inheritdoc}
262
     */
263 333
    public function hasUntilVersion()
264
    {
265 333
        return $this->until !== null;
266
    }
267
268
    /**
269
     * {@inheritdoc}
270
     */
271 333
    public function getUntilVersion()
272
    {
273 333
        return $this->until;
274
    }
275
276
    /**
277
     * {@inheritdoc}
278
     */
279 90
    public function setUntilVersion($until)
280
    {
281 90
        $this->until = $until;
282 90
    }
283
284
    /**
285
     * {@inheritdoc}
286
     */
287 309
    public function hasMaxDepth()
288
    {
289 309
        return $this->maxDepth !== null;
290
    }
291
292
    /**
293
     * {@inheritdoc}
294
     */
295 309
    public function getMaxDepth()
296
    {
297 309
        return $this->maxDepth;
298
    }
299
300
    /**
301
     * {@inheritdoc}
302
     */
303 66
    public function setMaxDepth($maxDepth)
304
    {
305 66
        $this->maxDepth = $maxDepth;
306 66
    }
307
308
    /**
309
     * {@inheritdoc}
310
     */
311 291
    public function hasGroups()
312
    {
313 291
        return !empty($this->groups);
314
    }
315
316
    /**
317
     * {@inheritdoc}
318
     */
319 294
    public function getGroups()
320
    {
321 294
        return array_keys($this->groups);
322
    }
323
324
    /**
325
     * {@inheritdoc}
326
     */
327 9
    public function setGroups(array $groups)
328
    {
329 9
        $this->groups = [];
330 9
        $this->addGroups($groups);
331 9
    }
332
333
    /**
334
     * {@inheritdoc}
335
     */
336 9
    public function addGroups(array $groups)
337
    {
338 9
        foreach ($groups as $group) {
339 9
            $this->addGroup($group);
340 6
        }
341 9
    }
342
343
    /**
344
     * {@inheritdoc}
345
     */
346 111
    public function hasGroup($group)
347
    {
348 111
        return isset($this->groups[$group]);
349
    }
350
351
    /**
352
     * {@inheritdoc}
353
     */
354 111
    public function addGroup($group)
355
    {
356 111
        if (!$this->hasGroup($group)) {
357 111
            $this->groups[$group] = true;
358 74
        }
359 111
    }
360
361
    /**
362
     * {@inheritdoc}
363
     */
364 3
    public function removeGroup($group)
365
    {
366 3
        unset($this->groups[$group]);
367 3
    }
368
369
    /**
370
     * {@inheritdoc}
371
     */
372 480
    public function isXmlAttribute()
373
    {
374 480
        return $this->xmlAttribute;
375
    }
376
377
    /**
378
     * {@inheritdoc}
379
     */
380 90
    public function setXmlAttribute($xmlAttribute)
381
    {
382 90
        $this->xmlAttribute = $xmlAttribute;
383 90
    }
384
385
    /**
386
     * {@inheritdoc}
387
     */
388 480
    public function isXmlValue()
389
    {
390 480
        return $this->xmlValue;
391
    }
392
393
    /**
394
     * {@inheritdoc}
395
     */
396 39
    public function setXmlValue($xmlValue)
397
    {
398 39
        $this->xmlValue = $xmlValue;
399 39
    }
400
401
    /**
402
     * {@inheritdoc}
403
     */
404 3
    public function merge(PropertyMetadataInterface $propertyMetadata)
405
    {
406 3
        $this->setReadable($propertyMetadata->isReadable());
407 3
        $this->setWritable($propertyMetadata->isWritable());
408 3
        $this->setXmlAttribute($propertyMetadata->isXmlAttribute());
409 3
        $this->setXmlValue($propertyMetadata->isXmlValue());
410
411 3
        if ($propertyMetadata->hasAlias()) {
412 3
            $this->setAlias($propertyMetadata->getAlias());
413 2
        }
414
415 3
        if ($propertyMetadata->hasType()) {
416 3
            $this->setType($propertyMetadata->getType());
417 2
        }
418
419 3
        if ($propertyMetadata->hasAccessor()) {
420 3
            $this->setAccessor($propertyMetadata->getAccessor());
421 2
        }
422
423 3
        if ($propertyMetadata->hasMutator()) {
424 3
            $this->setMutator($propertyMetadata->getMutator());
425 2
        }
426
427 3
        if ($propertyMetadata->hasSinceVersion()) {
428 3
            $this->setSinceVersion($propertyMetadata->getSinceVersion());
429 2
        }
430
431 3
        if ($propertyMetadata->hasUntilVersion()) {
432 3
            $this->setUntilVersion($propertyMetadata->getUntilVersion());
433 2
        }
434
435 3
        if ($propertyMetadata->hasMaxDepth()) {
436 3
            $this->setMaxDepth($propertyMetadata->getMaxDepth());
437 2
        }
438
439 3
        foreach ($propertyMetadata->getGroups() as $group) {
440 3
            $this->addGroup($group);
441 2
        }
442 3
    }
443
444
    /**
445
     * {@inheritdoc}
446
     */
447 3
    public function serialize()
448
    {
449 3
        return serialize([
450 3
            $this->name,
451 3
            $this->alias,
452 3
            $this->type,
453 3
            $this->readable,
454 3
            $this->writable,
455 3
            $this->accessor,
456 3
            $this->mutator,
457 3
            $this->since,
458 3
            $this->until,
459 3
            $this->maxDepth,
460 3
            $this->groups,
461 3
            $this->xmlAttribute,
462 3
            $this->xmlValue,
463 2
        ]);
464
    }
465
466
    /**
467
     * {@inheritdoc}
468
     */
469 3
    public function unserialize($serialized)
470
    {
471
        list(
472 3
            $this->name,
473 3
            $this->alias,
474 3
            $this->type,
475 3
            $this->readable,
476 3
            $this->writable,
477 3
            $this->accessor,
478 3
            $this->mutator,
479 3
            $this->since,
480 3
            $this->until,
481 3
            $this->maxDepth,
482 3
            $this->groups,
483 3
            $this->xmlAttribute,
484 3
            $this->xmlValue
485 3
        ) = unserialize($serialized);
486 3
    }
487
}
488