Completed
Pull Request — master (#58)
by Ilya
01:50
created

Serialize   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 27
rs 10
c 1
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A context() 0 4 1
A allowArray() 0 3 1
A __construct() 0 3 1
A getAliasName() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Damax\Common\Bridge\Symfony\Bundle\Annotation;
6
7
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationInterface;
8
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
9
10
/**
11
 * @Annotation
12
 */
13
final class Serialize implements ConfigurationInterface
14
{
15
    /**
16
     * @var bool
17
     */
18
    private $deepPopulate;
19
20
    public function __construct(array $data)
21
    {
22
        $this->deepPopulate = (bool) ($data['deepPopulate'] ?? $data['value']);
23
    }
24
25
    public function context(): array
26
    {
27
        return [
28
            AbstractObjectNormalizer::DEEP_OBJECT_TO_POPULATE => $this->deepPopulate,
29
        ];
30
    }
31
32
    public function getAliasName(): string
33
    {
34
        return 'serialize';
35
    }
36
37
    public function allowArray(): bool
38
    {
39
        return false;
40
    }
41
}
42