Type   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 8

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 23 8
1
<?php
2
3
declare(strict_types=1);
4
5
namespace JMS\Serializer\Annotation;
6
7
/**
8
 * @Annotation
9
 * @Target({"PROPERTY", "METHOD","ANNOTATION"})
10
 */
11
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
12
final class Type implements SerializerAttribute
13
{
14
    use AnnotationUtilsTrait;
15
16
    /**
17
     * @Required
18
     * @var string|\Stringable|null
19
     */
20
    public $name = null;
21
22
    public function __construct($values = [], $name = null)
23
    {
24
        if ((null !== $name) && !is_string($name) && !(is_object($name) && method_exists($name, '__toString'))) {
25
            throw new \RuntimeException(
26
                'Type must be either string, null or object implements __toString() method.',
27
            );
28
        }
29
30
        if (is_object($name)) {
31
            $name = (string) $name;
32
        }
33
34
        if (is_object($values)) {
35
            if (false === method_exists($values, '__toString')) {
36
                throw new \RuntimeException(
37
                    'Type must be either string or object implements __toString() method.',
38
                );
39
            }
40
41
            $values = (string) $values;
42
        }
43
44
        $this->loadAnnotationParameters(get_defined_vars());
45
    }
46
}
47