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

Deserialize::context()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
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\AbstractNormalizer;
9
10
/**
11
 * @Annotation
12
 */
13
final class Deserialize implements ConfigurationInterface
14
{
15
    /**
16
     * @var string
17
     */
18
    private $class;
19
20
    /**
21
     * @var array
22
     */
23
    private $ignore;
24
25
    /**
26
     * @var int
27
     */
28
    private $refLimit;
29
30
    /**
31
     * @var bool
32
     */
33
    private $allowExtra;
34
35
    /**
36
     * @var array
37
     */
38
    private $constructorArgs;
39
40
    /**
41
     * @var string
42
     */
43
    private $param;
44
45
    public function __construct(array $data)
46
    {
47
        $this->class = $data['class'] ?? $data['value'];
48
49
        $this->ignore = (array) ($data['ignore'] ?? []);
50
        $this->refLimit = (int) ($data['refLimit'] ?? 1);
51
        $this->allowExtra = (bool) ($data['allowExtra'] ?? true);
52
        $this->constructorArgs = (array) ($data['constructorArgs'] ?? []);
53
54
        $this->param = $data['param'] ?? 'data';
55
    }
56
57
    public function className(): string
58
    {
59
        return $this->class;
60
    }
61
62
    public function context(): array
63
    {
64
        return [
65
            AbstractNormalizer::IGNORED_ATTRIBUTES => $this->ignore,
66
            AbstractNormalizer::CIRCULAR_REFERENCE_LIMIT => $this->refLimit,
67
            AbstractNormalizer::ALLOW_EXTRA_ATTRIBUTES => $this->allowExtra,
68
            AbstractNormalizer::DEFAULT_CONSTRUCTOR_ARGUMENTS => $this->constructorArgs,
69
        ];
70
    }
71
72
    public function param(): string
73
    {
74
        return $this->param;
75
    }
76
77
    public function getAliasName(): string
78
    {
79
        return 'deserialize';
80
    }
81
82
    public function allowArray(): bool
83
    {
84
        return false;
85
    }
86
}
87