Info::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace BultonFr\Annotation\Parsers\Annotations;
4
5
/**
6
 * All info about an annotation.
7
 *
8
 * This class is used by Parsers\Annotations\Reader to save all data about an
9
 * annotation. While dev, it was a anonymous class. But I move it to a real
10
 * class to improve performences (definition is the more longer).
11
 *
12
 * @package BultonFr\Annotation
13
 */
14
class Info
15
{
16
    /**
17
     * The annotation name (the part just after the @)
18
     *
19
     * @var string
20
     */
21
    protected $name = '';
22
23
    /**
24
     * The annotation values on the string format.
25
     * (like writed into the class, without line-break)
26
     * It's the part after the annotation name.
27
     *
28
     * @var string
29
     */
30
    protected $valueStr = '';
31
32
    /**
33
     * All values parsed.
34
     *
35
     * @var array
36
     */
37
    protected $values = [];
38
39
    /**
40
     * Construct
41
     *
42
     * @param string $name
43
     * @param string $valueStr
44
     */
45
    public function __construct(string $name, string $valueStr)
46
    {
47 1
        $this->name     = $name;
48 1
        $this->valueStr = trim($valueStr);
49 1
    }
50
    
51
    /**
52
     * Get the annotation name (the part just after the @)
53
     *
54
     * @return string
55
     */
56
    public function getName(): string
57
    {
58 1
        return $this->name;
59
    }
60
61
    /**
62
     * Get the annotation values on the string format.
63
     * (like writed into the class, without line-break)
64
     * It's the part after the annotation name.
65
     *
66
     * @return string
67
     */
68
    public function getValueStr(): string
69
    {
70 1
        return $this->valueStr;
71
    }
72
73
    /**
74
     * Get all values parsed.
75
     *
76
     * @return array
77
     */
78
    public function getValues(): array
79
    {
80 1
        return $this->values;
81
    }
82
83
    /**
84
     * Set the annotation values on the string format.
85
     * (like writed into the class, without line-break)
86
     * It's the part after the annotation name.
87
     *
88
     * @param string $valueStr
89
     *
90
     * @return self
91
     */
92
    public function setValueStr(string $valueStr): self
93
    {
94 1
        $this->valueStr = $valueStr;
95 1
        return $this;
96
    }
97
98
    /**
99
     * Set all values parsed.
100
     *
101
     * @param array $values
102
     *
103
     * @return self
104
     */
105
    public function setValues(array $values): self
106
    {
107 1
        $this->values = $values;
108 1
        return $this;
109
    }
110
    
111
    /**
112
     * Add a value at the end of valueStr.
113
     * The new value will be added with a space at the beggining
114
     *
115
     * @param string $addedValue
116
     *
117
     * @return self
118
     */
119
    public function concatValueStr(string $addedValue): self
120
    {
121 1
        $addedValue = trim($addedValue);
122
        
123 1
        if (empty($addedValue) === false) {
124 1
            $this->valueStr .= ' '.$addedValue;
125
        }
126
        
127 1
        return $this;
128
    }
129
    
130
    /**
131
     * Add a new value to $values
132
     *
133
     * @param string|null $valueName The value attribute name
134
     * @param mixed $value
135
     *
136
     * @return self
137
     */
138
    public function addValue(?string $valueName, $value): self
139
    {
140 1
        if ($valueName === null) {
141 1
            $this->values[] = $value;
142
        } else {
143 1
            $this->values[$valueName] = $value;
144
        }
145
146 1
        return $this;
147
    }
148
}
149