CheckTrait::getImportance()   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
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
/**
4
 * This file is part of the `tvi/monitor-bundle` project.
5
 *
6
 * (c) https://github.com/turnaev/monitor-bundle/graphs/contributors
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
Coding Style introduced by
Missing @link tag in file comment
Loading history...
11
12
namespace Tvi\MonitorBundle\Check;
13
14
use JMS\Serializer\Annotation as JMS;
15
use ZendDiagnostics\Result\ResultInterface;
16
17
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
18
 * @author Vladimir Turnaev <[email protected]>
19
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
20
trait CheckTrait
21
{
22
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
23
     * @JMS\SerializedName("id")
24
     * @JMS\Expose()
25
     *
26
     * @var string
27
     */
28
    protected $id;
29
30
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
31
     * @var ?string
32
     */
33
    protected $label;
34
35
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
36
     * @JMS\SerializedName("group")
37
     * @JMS\Type("string")
38
     * @JMS\Expose()
39
     *
40
     * @var string
41
     */
42
    protected $group;
43
44
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
45
     * @JMS\SerializedName("descr")
46
     * @JMS\Type("string")
47
     * @JMS\SkipWhenEmpty()
48
     * @JMS\Expose()
49
     *
50
     * @var string?
0 ignored issues
show
Documentation Bug introduced by
The doc comment string? at position 0 could not be parsed: Unknown type name 'string?' at position 0 in string?.
Loading history...
51
     */
52
    protected $descr;
53
54
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
55
     * @JMS\SerializedName("importance")
56
     * @JMS\SkipWhenEmpty()
57
     * @JMS\Type("string")
58
     * @JMS\Expose()
59
     *
60
     * @var ?string
61
     */
62
    protected $importance;
63
64
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
65
     * @JMS\SerializedName("tags")
66
     * @JMS\SkipWhenEmpty()
67
     * @JMS\Type("array<string>")
68
     * @JMS\Expose()
69
     *
70
     * @var string[]
71
     */
72
    protected $tags = [];
73
74
    /**
75
     * Perform the actual check and return a ResultInterface.
76
     *
77
     * @return ResultInterface
78
     */
79
    abstract public function check();
80
81 71
    public function getId(): string
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getId()
Loading history...
82
    {
83 71
        return $this->id;
84
    }
85
86 139
    public function setId(string $id)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function setId()
Loading history...
87
    {
88 139
        $this->id = $id;
89 139
    }
90
91 47
    public function getImportance()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getImportance()
Loading history...
92
    {
93 47
        return $this->importance;
94
    }
95
96 113
    public function setImportance($importance)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function setImportance()
Loading history...
97
    {
98 113
        $this->importance = $importance;
99 113
    }
100
101
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
102
     * @return string[]
103
     */
104 53
    public function getTags(): array
105
    {
106 53
        return $this->tags;
107
    }
108
109
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
110
     * @param string[] $tags
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
111
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
112 118
    public function setTags(array $tags)
113
    {
114 118
        $this->tags = $tags;
115 118
        $this->tags = array_unique($this->tags);
116 118
    }
117
118
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
119
     * @param string $tag
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
120
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
121
    public function addTag($tag)
122
    {
123
        $this->tags[$tag];
124
        $this->tags = array_unique($this->tags);
125
    }
126
127 53
    public function getGroup(): string
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getGroup()
Loading history...
128
    {
129 53
        return $this->group;
130
    }
131
132 118
    public function setGroup(string $group)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function setGroup()
Loading history...
133
    {
134 118
        $this->group = $group;
135 118
    }
136
137
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
138
     * @JMS\SerializedName("label")
139
     * @JMS\Type("string")
140
     * @JMS\VirtualProperty()
141
     * @JMS\Expose()
142
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
143 59
    public function getLabel(): string
144
    {
145 59
        if (null !== $this->label) {
146 13
            return $this->label;
147
        }
148
149 54
        return sprintf('Check %s', $this->id);
150
    }
151
152 118
    public function setLabel($label)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function setLabel()
Loading history...
153
    {
154 118
        $this->label = $label;
155 118
    }
156
157
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
158
     * @return ?string
159
     */
160
    public function getDescr()
161
    {
162
        return $this->descr;
163
    }
164
165
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
166
     * @param ?string $descr
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
167
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
168 113
    public function setDescr(string $descr = null)
169
    {
170 113
        $this->descr = $descr;
171 113
    }
172
173 114
    public function setAdditionParams(array $data)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function setAdditionParams()
Loading history...
174
    {
175 114
        if (array_key_exists('id', $data)) {
176 114
            $this->setId($data['id']);
177
        }
178
179 114
        if (array_key_exists('group', $data)) {
180 114
            $this->setGroup($data['group']);
181
        }
182
183 114
        if (array_key_exists('importance', $data)) {
184 113
            $this->setImportance($data['importance']);
185
        }
186
187 114
        if (array_key_exists('tags', $data)) {
188 114
            $this->setTags($data['tags']);
189
        }
190
191 114
        if (array_key_exists('label', $data)) {
192 114
            $this->setLabel($data['label']);
193
        }
194
195 114
        if (array_key_exists('descr', $data)) {
196 113
            $this->setDescr($data['descr']);
197
        }
198 114
    }
199
}
200