Passed
Pull Request — master (#1332)
by Asmir
02:29
created

Discriminator::__construct()   A

Complexity

Conditions 5
Paths 16

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 12
nc 16
nop 5
dl 0
loc 22
rs 9.5555
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace JMS\Serializer\Annotation;
6
7
/**
8
 * @Annotation
9
 * @Target("CLASS")
10
 */
11
#[\Attribute(\Attribute::TARGET_CLASS)]
12
class Discriminator
13
{
14
    /** @var array<string> */
15
    public $map = [];
16
17
    /** @var string */
18
    public $field = 'type';
19
20
    /** @var bool */
21
    public $disabled = false;
22
23
    /** @var string[] */
24
    public $groups = [];
25
26
    public function __construct(array $values = [], string $field = 'type', array $groups = [], array $map = [], bool $disabled = false)
27
    {
28
        if (array_key_exists('field', $values)) {
29
            $field = $values['field'];
30
        }
31
32
        if (array_key_exists('groups', $values)) {
33
            $groups = $values['groups'];
34
        }
35
36
        if (array_key_exists('map', $values)) {
37
            $map = $values['map'];
38
        }
39
40
        if (array_key_exists('disabled', $values)) {
41
            $disabled = $values['disabled'];
42
        }
43
44
        $this->field = $field;
45
        $this->groups = $groups;
46
        $this->map = $map;
47
        $this->disabled = $disabled;
48
    }
49
}
50