BaseGroupLoader   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 22
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A loadClassMetadata() 0 10 4
1
<?php
2
3
namespace Apie\CorePlugin\Mapping;
4
5
use Symfony\Component\Serializer\Mapping\ClassMetadataInterface;
6
use Symfony\Component\Serializer\Mapping\Loader\LoaderInterface;
7
8
/**
9
 * Decorator for the Symfony serializer to always add a default group to all the properties.
10
 * The default behaviour is to ignore properties with no serialization group.
11
 */
12
class BaseGroupLoader implements LoaderInterface
13
{
14
    private $groups;
15
16
    public function __construct(array $groups)
17
    {
18
        $this->groups = $groups;
19
    }
20
21
    /**
22
     * @return bool
23
     */
24
    public function loadClassMetadata(ClassMetadataInterface $classMetadata)
25
    {
26
        foreach ($classMetadata->getAttributesMetadata() as $metadata) {
27
            if (empty($metadata->getGroups())) {
28
                foreach ($this->groups as $group) {
29
                    $metadata->addGroup($group);
30
                }
31
            }
32
        }
33
        return true;
34
    }
35
}
36