Completed
Push — master ( b2d2e1...8cfc77 )
by Vladimir
06:29
created

Group::setDescr()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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