Completed
Push — master ( ca3dd9...004b26 )
by Vladimir
08:32 queued 02:34
created

Group::getCheckIds()   A

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