Completed
Pull Request — master (#11)
by Eric
62:01
created

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