PropertyMetadata   F
last analyzed

Complexity

Total Complexity 87

Size/Duplication

Total Lines 714
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 714
c 0
b 0
f 0
wmc 87
lcom 1
cbo 1
ccs 226
cts 226
cp 1
rs 1.886

63 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getName() 0 4 1
A setName() 0 4 1
A getClass() 0 4 1
A setClass() 0 4 1
A hasAlias() 0 4 1
A getAlias() 0 4 1
A setAlias() 0 4 1
A hasType() 0 4 1
A getType() 0 4 1
A setType() 0 4 1
A hasReadable() 0 4 1
A isReadable() 0 4 2
A setReadable() 0 4 1
A hasWritable() 0 4 1
A isWritable() 0 4 2
A setWritable() 0 4 1
A hasAccessor() 0 4 1
A getAccessor() 0 4 1
A setAccessor() 0 4 1
A hasMutator() 0 4 1
A getMutator() 0 4 1
A setMutator() 0 4 1
A hasSinceVersion() 0 4 1
A getSinceVersion() 0 4 1
A setSinceVersion() 0 4 1
A hasUntilVersion() 0 4 1
A getUntilVersion() 0 4 1
A setUntilVersion() 0 4 1
A hasMaxDepth() 0 4 1
A getMaxDepth() 0 4 1
A setMaxDepth() 0 4 1
A hasGroups() 0 4 1
A getGroups() 0 4 1
A setGroups() 0 5 1
A addGroups() 0 6 2
A hasGroup() 0 4 1
A addGroup() 0 6 2
A removeGroup() 0 4 1
A hasXmlAttribute() 0 4 1
A isXmlAttribute() 0 4 2
A setXmlAttribute() 0 4 1
A hasXmlValue() 0 4 1
A isXmlValue() 0 4 2
A setXmlValue() 0 4 1
A hasXmlInline() 0 4 1
A isXmlInline() 0 4 2
A setXmlInline() 0 4 1
A hasXmlEntry() 0 4 1
A getXmlEntry() 0 4 1
A setXmlEntry() 0 4 1
A hasXmlEntryAttribute() 0 4 1
A getXmlEntryAttribute() 0 4 1
A setXmlEntryAttribute() 0 4 1
A hasXmlKeyAsAttribute() 0 4 1
A useXmlKeyAsAttribute() 0 4 1
A setXmlKeyAsAttribute() 0 4 1
A hasXmlKeyAsNode() 0 4 1
A useXmlKeyAsNode() 0 4 1
A setXmlKeyAsNode() 0 4 1
F merge() 0 70 18
A serialize() 0 24 1
A unserialize() 0 24 1

How to fix   Complexity   

Complex Class

Complex classes like PropertyMetadata often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use PropertyMetadata, and based on these observations, apply Extract Interface, too.

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 $class;
28
29
    /**
30
     * @var string
31
     */
32
    private $alias;
33
34
    /**
35
     * @var TypeMetadataInterface|null
36
     */
37
    private $type;
38
39
    /**
40
     * @var bool|null
41
     */
42
    private $readable;
43
44
    /**
45
     * @var bool|null
46
     */
47
    private $writable;
48
49
    /**
50
     * @var string|null
51
     */
52
    private $accessor;
53
54
    /**
55
     * @var string|null
56
     */
57
    private $mutator;
58
59
    /**
60
     * @var string|null
61
     */
62
    private $since;
63
64
    /**
65
     * @var string|null
66
     */
67
    private $until;
68
69
    /**
70
     * @var int|null
71
     */
72
    private $maxDepth;
73
74
    /**
75
     * @var string[]
76
     */
77
    private $groups = [];
78
79
    /**
80
     * @var bool|null
81
     */
82
    private $xmlAttribute;
83
84
    /**
85
     * @var bool|null
86
     */
87
    private $xmlValue;
88
89
    /**
90
     * @var bool|null
91
     */
92
    private $xmlInline;
93
94
    /**
95
     * @var string|null
96
     */
97
    private $xmlEntry;
98
99
    /**
100
     * @var string|null
101
     */
102
    private $xmlEntryAttribute;
103
104
    /**
105
     * @var bool|null
106
     */
107
    private $xmlKeyAsAttribute;
108
109
    /**
110
     * @var bool|null
111
     */
112
    private $xmlKeyAsNode;
113
114
    /**
115
     * @param string $name
116
     * @param string $class
117
     */
118 1908
    public function __construct($name, $class)
119
    {
120 1908
        $this->setName($name);
121 1908
        $this->setClass($class);
122 1908
    }
123
124
    /**
125
     * {@inheritdoc}
126
     */
127 1820
    public function getName()
128
    {
129 1820
        return $this->name;
130
    }
131
132
    /**
133
     * {@inheritdoc}
134
     */
135 1908
    public function setName($name)
136
    {
137 1908
        $this->name = $name;
138 1908
    }
139
140
    /**
141
     * {@inheritdoc}
142
     */
143 8
    public function getClass()
144
    {
145 8
        return $this->class;
146
    }
147
148
    /**
149
     * {@inheritdoc}
150
     */
151 1908
    public function setClass($class)
152
    {
153 1908
        $this->class = $class;
154 1908
    }
155
156
    /**
157
     * {@inheritdoc}
158
     */
159 1724
    public function hasAlias()
160
    {
161 1724
        return $this->alias !== null;
162
    }
163
164
    /**
165
     * {@inheritdoc}
166
     */
167 764
    public function getAlias()
168
    {
169 764
        return $this->alias;
170
    }
171
172
    /**
173
     * {@inheritdoc}
174
     */
175 168
    public function setAlias($alias)
176
    {
177 168
        $this->alias = $alias;
178 168
    }
179
180
    /**
181
     * {@inheritdoc}
182
     */
183 636
    public function hasType()
184
    {
185 636
        return $this->type !== null;
186
    }
187
188
    /**
189
     * {@inheritdoc}
190
     */
191 1252
    public function getType()
192
    {
193 1252
        return $this->type;
194
    }
195
196
    /**
197
     * {@inheritdoc}
198
     */
199 1280
    public function setType(TypeMetadataInterface $type = null)
200
    {
201 1280
        $this->type = $type;
202 1280
    }
203
204
    /**
205
     * {@inheritdoc}
206
     */
207 1308
    public function hasReadable()
208
    {
209 1308
        return $this->readable !== null;
210
    }
211
212
    /**
213
     * {@inheritdoc}
214
     */
215 1308
    public function isReadable()
216
    {
217 1308
        return !$this->hasReadable() || $this->readable;
218
    }
219
220
    /**
221
     * {@inheritdoc}
222
     */
223 136
    public function setReadable($readable)
224
    {
225 136
        $this->readable = $readable;
226 136
    }
227
228
    /**
229
     * {@inheritdoc}
230
     */
231 1024
    public function hasWritable()
232
    {
233 1024
        return $this->writable !== null;
234
    }
235
236
    /**
237
     * {@inheritdoc}
238
     */
239 1024
    public function isWritable()
240
    {
241 1024
        return !$this->hasWritable() || $this->writable;
242
    }
243
244
    /**
245
     * {@inheritdoc}
246
     */
247 136
    public function setWritable($writable)
248
    {
249 136
        $this->writable = $writable;
250 136
    }
251
252
    /**
253
     * {@inheritdoc}
254
     */
255 1308
    public function hasAccessor()
256
    {
257 1308
        return $this->accessor !== null;
258
    }
259
260
    /**
261
     * {@inheritdoc}
262
     */
263 652
    public function getAccessor()
264
    {
265 652
        return $this->accessor;
266
    }
267
268
    /**
269
     * {@inheritdoc}
270
     */
271 72
    public function setAccessor($accessor)
272
    {
273 72
        $this->accessor = $accessor;
274 72
    }
275
276
    /**
277
     * {@inheritdoc}
278
     */
279 964
    public function hasMutator()
280
    {
281 964
        return $this->mutator !== null;
282
    }
283
284
    /**
285
     * {@inheritdoc}
286
     */
287 652
    public function getMutator()
288
    {
289 652
        return $this->mutator;
290
    }
291
292
    /**
293
     * {@inheritdoc}
294
     */
295 72
    public function setMutator($mutator)
296
    {
297 72
        $this->mutator = $mutator;
298 72
    }
299
300
    /**
301
     * {@inheritdoc}
302
     */
303 700
    public function hasSinceVersion()
304
    {
305 700
        return $this->since !== null;
306
    }
307
308
    /**
309
     * {@inheritdoc}
310
     */
311 700
    public function getSinceVersion()
312
    {
313 700
        return $this->since;
314
    }
315
316
    /**
317
     * {@inheritdoc}
318
     */
319 136
    public function setSinceVersion($since)
320
    {
321 136
        $this->since = $since;
322 136
    }
323
324
    /**
325
     * {@inheritdoc}
326
     */
327 700
    public function hasUntilVersion()
328
    {
329 700
        return $this->until !== null;
330
    }
331
332
    /**
333
     * {@inheritdoc}
334
     */
335 700
    public function getUntilVersion()
336
    {
337 700
        return $this->until;
338
    }
339
340
    /**
341
     * {@inheritdoc}
342
     */
343 136
    public function setUntilVersion($until)
344
    {
345 136
        $this->until = $until;
346 136
    }
347
348
    /**
349
     * {@inheritdoc}
350
     */
351 668
    public function hasMaxDepth()
352
    {
353 668
        return $this->maxDepth !== null;
354
    }
355
356
    /**
357
     * {@inheritdoc}
358
     */
359 668
    public function getMaxDepth()
360
    {
361 668
        return $this->maxDepth;
362
    }
363
364
    /**
365
     * {@inheritdoc}
366
     */
367 104
    public function setMaxDepth($maxDepth)
368
    {
369 104
        $this->maxDepth = $maxDepth;
370 104
    }
371
372
    /**
373
     * {@inheritdoc}
374
     */
375 692
    public function hasGroups()
376
    {
377 692
        return !empty($this->groups);
378
    }
379
380
    /**
381
     * {@inheritdoc}
382
     */
383 648
    public function getGroups()
384
    {
385 648
        return array_keys($this->groups);
386
    }
387
388
    /**
389
     * {@inheritdoc}
390
     */
391 12
    public function setGroups(array $groups)
392
    {
393 12
        $this->groups = [];
394 12
        $this->addGroups($groups);
395 12
    }
396
397
    /**
398
     * {@inheritdoc}
399
     */
400 156
    public function addGroups(array $groups)
401
    {
402 156
        foreach ($groups as $group) {
403 156
            $this->addGroup($group);
404
        }
405 156
    }
406
407
    /**
408
     * {@inheritdoc}
409
     */
410 164
    public function hasGroup($group)
411
    {
412 164
        return isset($this->groups[$group]);
413
    }
414
415
    /**
416
     * {@inheritdoc}
417
     */
418 164
    public function addGroup($group)
419
    {
420 164
        if (!$this->hasGroup($group)) {
421 164
            $this->groups[$group] = true;
422
        }
423 164
    }
424
425
    /**
426
     * {@inheritdoc}
427
     */
428 4
    public function removeGroup($group)
429
    {
430 4
        unset($this->groups[$group]);
431 4
    }
432
433
    /**
434
     * {@inheritdoc}
435
     */
436 904
    public function hasXmlAttribute()
437
    {
438 904
        return $this->xmlAttribute !== null;
439
    }
440
441
    /**
442
     * {@inheritdoc}
443
     */
444 904
    public function isXmlAttribute()
445
    {
446 904
        return $this->hasXmlAttribute() && $this->xmlAttribute;
447
    }
448
449
    /**
450
     * {@inheritdoc}
451
     */
452 136
    public function setXmlAttribute($xmlAttribute)
453
    {
454 136
        $this->xmlAttribute = $xmlAttribute;
455 136
    }
456
457
    /**
458
     * {@inheritdoc}
459
     */
460 904
    public function hasXmlValue()
461
    {
462 904
        return $this->xmlValue !== null;
463
    }
464
465
    /**
466
     * {@inheritdoc}
467
     */
468 904
    public function isXmlValue()
469
    {
470 904
        return $this->hasXmlValue() && $this->xmlValue;
471
    }
472
473
    /**
474
     * {@inheritdoc}
475
     */
476 72
    public function setXmlValue($xmlValue)
477
    {
478 72
        $this->xmlValue = $xmlValue;
479 72
    }
480
481
    /**
482
     * {@inheritdoc}
483
     */
484 900
    public function hasXmlInline()
485
    {
486 900
        return $this->xmlInline !== null;
487
    }
488
489
    /**
490
     * {@inheritdoc}
491
     */
492 900
    public function isXmlInline()
493
    {
494 900
        return $this->hasXmlInline() && $this->xmlInline;
495
    }
496
497
    /**
498
     * {@inheritdoc}
499
     */
500 72
    public function setXmlInline($xmlInline)
501
    {
502 72
        $this->xmlInline = $xmlInline;
503 72
    }
504
505
    /**
506
     * {@inheritdoc}
507
     */
508 48
    public function hasXmlEntry()
509
    {
510 48
        return $this->xmlEntry !== null;
511
    }
512
513
    /**
514
     * {@inheritdoc}
515
     */
516 644
    public function getXmlEntry()
517
    {
518 644
        return $this->xmlEntry;
519
    }
520
521
    /**
522
     * {@inheritdoc}
523
     */
524 72
    public function setXmlEntry($xmlEntry)
525
    {
526 72
        $this->xmlEntry = $xmlEntry;
527 72
    }
528
529
    /**
530
     * {@inheritdoc}
531
     */
532 48
    public function hasXmlEntryAttribute()
533
    {
534 48
        return $this->xmlEntryAttribute !== null;
535
    }
536
537
    /**
538
     * {@inheritdoc}
539
     */
540 644
    public function getXmlEntryAttribute()
541
    {
542 644
        return $this->xmlEntryAttribute;
543
    }
544
545
    /**
546
     * {@inheritdoc}
547
     */
548 72
    public function setXmlEntryAttribute($xmlEntryAttribute)
549
    {
550 72
        $this->xmlEntryAttribute = $xmlEntryAttribute;
551 72
    }
552
553
    /**
554
     * {@inheritdoc}
555
     */
556 48
    public function hasXmlKeyAsAttribute()
557
    {
558 48
        return $this->xmlKeyAsAttribute !== null;
559
    }
560
561
    /**
562
     * {@inheritdoc}
563
     */
564 644
    public function useXmlKeyAsAttribute()
565
    {
566 644
        return $this->xmlKeyAsAttribute;
567
    }
568
569
    /**
570
     * {@inheritdoc}
571
     */
572 72
    public function setXmlKeyAsAttribute($xmlKeyAsAttribute)
573
    {
574 72
        $this->xmlKeyAsAttribute = $xmlKeyAsAttribute;
575 72
    }
576
577
    /**
578
     * {@inheritdoc}
579
     */
580 40
    public function hasXmlKeyAsNode()
581
    {
582 40
        return $this->xmlKeyAsNode !== null;
583
    }
584
585
    /**
586
     * {@inheritdoc}
587
     */
588 644
    public function useXmlKeyAsNode()
589
    {
590 644
        return $this->xmlKeyAsNode;
591
    }
592
593
    /**
594
     * {@inheritdoc}
595
     */
596 72
    public function setXmlKeyAsNode($xmlKeyAsNode)
597
    {
598 72
        $this->xmlKeyAsNode = $xmlKeyAsNode;
599 72
    }
600
601
    /**
602
     * {@inheritdoc}
603
     */
604 4
    public function merge(PropertyMetadataInterface $propertyMetadata)
605
    {
606 4
        if ($propertyMetadata->hasAlias()) {
607 4
            $this->setAlias($propertyMetadata->getAlias());
608
        }
609
610 4
        if ($propertyMetadata->hasType()) {
611 4
            $this->setType($propertyMetadata->getType());
612
        }
613
614 4
        if ($propertyMetadata->hasReadable()) {
615 4
            $this->setReadable($propertyMetadata->isReadable());
616
        }
617
618 4
        if ($propertyMetadata->hasWritable()) {
619 4
            $this->setWritable($propertyMetadata->isWritable());
620
        }
621
622 4
        if ($propertyMetadata->hasAccessor()) {
623 4
            $this->setAccessor($propertyMetadata->getAccessor());
624
        }
625
626 4
        if ($propertyMetadata->hasMutator()) {
627 4
            $this->setMutator($propertyMetadata->getMutator());
628
        }
629
630 4
        if ($propertyMetadata->hasSinceVersion()) {
631 4
            $this->setSinceVersion($propertyMetadata->getSinceVersion());
632
        }
633
634 4
        if ($propertyMetadata->hasUntilVersion()) {
635 4
            $this->setUntilVersion($propertyMetadata->getUntilVersion());
636
        }
637
638 4
        if ($propertyMetadata->hasMaxDepth()) {
639 4
            $this->setMaxDepth($propertyMetadata->getMaxDepth());
640
        }
641
642 4
        foreach ($propertyMetadata->getGroups() as $group) {
643 4
            $this->addGroup($group);
644
        }
645
646 4
        if ($propertyMetadata->hasXmlAttribute()) {
647 4
            $this->setXmlAttribute($propertyMetadata->isXmlAttribute());
648
        }
649
650 4
        if ($propertyMetadata->hasXmlValue()) {
651 4
            $this->setXmlValue($propertyMetadata->isXmlValue());
652
        }
653
654 4
        if ($propertyMetadata->hasXmlInline()) {
655 4
            $this->setXmlInline($propertyMetadata->isXmlInline());
656
        }
657
658 4
        if ($propertyMetadata->hasXmlEntry()) {
659 4
            $this->setXmlEntry($propertyMetadata->getXmlEntry());
660
        }
661
662 4
        if ($propertyMetadata->hasXmlEntryAttribute()) {
663 4
            $this->setXmlEntryAttribute($propertyMetadata->getXmlEntryAttribute());
664
        }
665
666 4
        if ($propertyMetadata->hasXmlKeyAsAttribute()) {
667 4
            $this->setXmlKeyAsAttribute($propertyMetadata->useXmlKeyAsAttribute());
668
        }
669
670 4
        if ($propertyMetadata->hasXmlKeyAsNode()) {
671 4
            $this->setXmlKeyAsNode($propertyMetadata->useXmlKeyAsNode());
672
        }
673 4
    }
674
675
    /**
676
     * {@inheritdoc}
677
     */
678 4
    public function serialize()
679
    {
680 4
        return serialize([
681 4
            $this->name,
682 4
            $this->class,
683 4
            $this->alias,
684 4
            $this->type,
685 4
            $this->readable,
686 4
            $this->writable,
687 4
            $this->accessor,
688 4
            $this->mutator,
689 4
            $this->since,
690 4
            $this->until,
691 4
            $this->maxDepth,
692 4
            $this->groups,
693 4
            $this->xmlAttribute,
694 4
            $this->xmlValue,
695 4
            $this->xmlInline,
696 4
            $this->xmlEntry,
697 4
            $this->xmlEntryAttribute,
698 4
            $this->xmlKeyAsAttribute,
699 4
            $this->xmlKeyAsNode,
700
        ]);
701
    }
702
703
    /**
704
     * {@inheritdoc}
705
     */
706 4
    public function unserialize($serialized)
707
    {
708
        list(
709 4
            $this->name,
710 4
            $this->class,
711 4
            $this->alias,
712 4
            $this->type,
713 4
            $this->readable,
714 4
            $this->writable,
715 4
            $this->accessor,
716 4
            $this->mutator,
717 4
            $this->since,
718 4
            $this->until,
719 4
            $this->maxDepth,
720 4
            $this->groups,
721 4
            $this->xmlAttribute,
722 4
            $this->xmlValue,
723 4
            $this->xmlInline,
724 4
            $this->xmlEntry,
725 4
            $this->xmlEntryAttribute,
726 4
            $this->xmlKeyAsAttribute,
727 4
            $this->xmlKeyAsNode
728 4
        ) = unserialize($serialized);
729 4
    }
730
}
731