BaseGroupLoader::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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