Test Failed
Push — master ( 3e1f63...b2d2e1 )
by Vladimir
04:38
created

Group::getDescr()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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
16
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
17
 * @JMS\AccessorOrder("custom", custom = {"id", "name", "label", "descr", "count"})
18
 * @JMS\VirtualProperty(
19
 *     exp="object.count()",
20
 *     options={@JMS\SerializedName("count")}
21
 *  )
22
 * @author Vladimir Turnaev <[email protected]>
0 ignored issues
show
Coding Style introduced by
Tag value indented incorrectly; expected 22 spaces but found 1
Loading history...
23
 */
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...
24
class Group implements \ArrayAccess, \Iterator, \Countable
25
{
26 94
    use CheckArraybleTrait;
27
28 94
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
29 94
     * @JMS\Exclude()
30
     *
31 84
     * @var CheckInterface[]
32
     */
33 84
    protected $checks = [];
34
35
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
36
     * @JMS\SerializedName("id")
37
     * @JMS\Type("string")
38
     *
39
     * @var string
40 94
     */
41
    protected $id;
42 94
43 94
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
44
     * @JMS\SerializedName("name")
45
     * @JMS\Type("string")
46
     *
47
     * @var string
48 1
     */
49
    protected $name;
50 1
51
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
52
     * @JMS\SerializedName("descr")
53
     * @JMS\Type("string")
54
     * @JMS\SkipWhenEmpty()
55
     *
56 2
     * @var ?string
57
     */
58 2
    protected $descr;
59
60
    public function __construct(string $id, ?string $name = null, ?string $descr = null)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
61
    {
62
        $this->id = $id;
63
        $this->name = null === $name ? $id : $name;
64
        $this->descr = $descr;
65
    }
66
67
    public function getId(): string
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getId()
Loading history...
68
    {
69
        return $this->id;
70
    }
71
72
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
73
     * @param mixed $name
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
74
     *
75
     * @return $this
76
     */
77
    public function setName(string $name): self
78
    {
79
        $this->name = $name;
80
81
        return $this;
82
    }
83
84
    public function getName(): string
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getName()
Loading history...
85
    {
86
        return $this->name;
87
    }
88
89
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
90
     * @param mixed $descr
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
91
     *
92
     * @return $this
93
     */
94
    public function setDescr(?string $descr): self
95
    {
96
        $this->descr = $descr;
97
98
        return $this;
99
    }
100
101
    public function getDescr(): ?string
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getDescr()
Loading history...
102
    {
103
        return $this->descr;
104
    }
105
106
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $checkId should have a doc-comment as per coding-style.
Loading history...
107
     * @param CheckInterface|Proxy $check
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Doc comment for parameter $check does not match actual variable name $checkId
Loading history...
108
     *
109
     * @return $this
110
     */
111
    public function addCheck(string $checkId, &$check): self
112
    {
113
        $this->checks[$checkId] = &$check;
114
115
        return $this;
116
    }
117
118
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
119
     * @JMS\SerializedName("label")
120
     * @JMS\Type("string")
121
     * @JMS\VirtualProperty()
122
     *
123
     * @return string
124
     */
125
    public function getLabel()
126
    {
127
        return sprintf('%s(%d)', $this->name, $this->count());
128
    }
129
130
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
131
     * @JMS\SerializedName("checks")
132
     * @JMS\SkipWhenEmpty()
133
     * @JMS\Type("array<string>")
134
     * @JMS\VirtualProperty()
135
     *
136
     * @return string[]
137
     */
138
    public function getCheckIds(): array
139
    {
140
        return array_keys($this->checks);
141
    }
142
}
143