Passed
Pull Request — master (#1337)
by Asmir
02:46
created

VirtualProperty::__construct()   A

Complexity

Conditions 5
Paths 6

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 10
nc 6
nop 4
dl 0
loc 18
rs 9.6111
c 1
b 0
f 0
ccs 1
cts 1
cp 1
crap 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace JMS\Serializer\Annotation;
6
7
/**
8
 * @Annotation
9
 * @Target({"METHOD", "CLASS"})
10
 *
11
 * @author Alexander Klimenkov <[email protected]>
12
 */
13
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
14
final class VirtualProperty
15
{
16
    use AnnotationUtilsTrait;
17
18
    /**
19
     * @var string|null
20
     */
21 36
    public $exp = null;
22
23 36
    /**
24 8
     * @var string|null
25 8
     */
26
    public $name = null;
27
28 36
    /**
29 9
     * @var array
30
     */
31
    public $options = [];
32 9
33
    public function __construct($values = [], ?string $name = null, ?string $exp = null, array $options = [])
34 36
    {
35
        $vars = get_defined_vars();
36
        unset($vars['options']);
37
        $this->loadAnnotationParameters($vars);
38
39
        if (0 !== count($options)) {
40
            $this->options = $options;
41
        }
42
43
        foreach ($options as $option) {
44
            if (is_array($option) && class_exists($option[0])) {
45
                $this->options[] = new $option[0]([], ...$option[1]);
46
47
                continue;
48
            }
49
50
            $this->options[] = $option;
51
        }
52
    }
53
}
54