AnnotationParsed::__isset()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace SimpleAnnotation;
4
5
use phpDocumentor\Reflection\Types\This;
6
use SimpleAnnotation\Concerns\ParsedAnnotationInterface;
7
8
/**
9
 * A model class to manipulate the annotations parsed values.
10
 * The abstraction of \JsonSerializable is necessary to the \SimpleAnnotation\Concerns\Cache\FileCache implementation.
11
 *
12
 * @package SimpleAnnotation
13
 */
14
final class AnnotationParsed implements ParsedAnnotationInterface, \JsonSerializable
15
{
16
    /** @var array */
17
    private array $properties = [];
18
19
    /**
20
     * Magic method.
21
     *
22
     * @param string $name
23
     * @return bool
24
     */
25 1
    public function __isset(string $name) : bool
26
    {
27 1
        return isset($this->properties[$name]);
28
    }
29
30
    /**
31
     * Magic method.
32
     *
33
     * @param string $name
34
     * @param $value
35
     */
36 25
    public function __set(string $name, $value)
37
    {
38 25
        if (!isset($this->properties[$name])) {
39 25
            $this->properties[$name] = $value;
40
        } else {
41 7
            if (is_array($this->properties[$name])) {
42 7
                $this->properties[$name][] = $value;
43
            } else {
44 7
                $this->properties[$name] = [$this->properties[$name], $value];
45
            }
46
        }
47 25
    }
48
49
    /**
50
     * Magic method.
51
     *
52
     * @param string $name
53
     * @return mixed
54
     */
55 9
    public function __get(string $name)
56
    {
57 9
        return $this->properties[$name];
58
    }
59
60
    /**
61
     * Stub method of \JsonSerializable.
62
     *
63
     * @return array
64
     */
65 5
    public function jsonSerialize()
66
    {
67 5
        return get_object_vars($this);
68
    }
69
70 5
    public function isEmpty(): bool
71
    {
72 5
        return empty($this->properties);
73
    }
74
}
75