Passed
Push — master ( de2c19...fed924 )
by Asmir
02:39 queued 12s
created

AnnotationUtilsTrait::loadAnnotationParameters()   B

Complexity

Conditions 7
Paths 36

Size

Total Lines 27
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 16
nc 36
nop 1
dl 0
loc 27
rs 8.8333
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace JMS\Serializer\Annotation;
6
7
use JMS\Serializer\Exception\InvalidArgumentException;
8
9
trait AnnotationUtilsTrait
10
{
11
    private function loadAnnotationParameters(array $vars): void
12
    {
13
        if (!array_key_exists('values', $vars)) {
14
            $values = [];
15
        } elseif (!is_array($vars['values'])) {
16
            $values = ['value' => $vars['values']];
17
        } else {
18
            $values = $vars['values'];
19
        }
20
21
        unset($vars['values']);
22
23
        if (array_key_exists('value', $values)) {
24
            $values[key($vars)] = $values['value'];
25
            unset($values['value']);
26
        }
27
28
        foreach ($values as $key => $value) {
29
            $vars[$key] = $value;
30
        }
31
32
        foreach ($vars as $key => $value) {
33
            if (!property_exists(static::class, $key)) {
34
                throw new InvalidArgumentException(sprintf('Unknown property "%s" on annotation "%s".', $key, static::class));
35
            }
36
37
            $this->{$key} = $value;
38
        }
39
    }
40
}
41