Group::getId()   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
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
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $id should have a doc-comment as per coding-style.
Loading history...
55
     * Group constructor.
56
     *
57
     * @param ?string $name
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Doc comment for parameter $name does not match actual variable name $id
Loading history...
58
     * @param ?string $descr
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Doc comment for parameter $descr does not match actual variable name $name
Loading history...
59
     */
60 146
    public function __construct(string $id, string $name = null, string $descr = null)
61
    {
62 146
        $this->id = $id;
63 146
        $this->name = null === $name ? $id : $name;
64 146
        $this->descr = $descr;
65 146
    }
66
67 133
    public function getId(): string
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getId()
Loading history...
68
    {
69 133
        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 1
    public function setName(string $name): self
78
    {
79 1
        $this->name = $name;
80
81 1
        return $this;
82
    }
83
84 133
    public function getName(): string
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getName()
Loading history...
85
    {
86 133
        return $this->name;
87
    }
88
89
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
90
     * @param ?string $descr
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
91
     *
92
     * @return $this
93
     */
94 1
    public function setDescr(string $descr = null): self
95
    {
96 1
        $this->descr = $descr;
97
98 1
        return $this;
99
    }
100
101
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
102
     * @return null|string
103
     */
104 1
    public function getDescr()
105
    {
106 1
        return $this->descr;
107
    }
108
109
    /**
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...
110
     * @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...
111
     *
112
     * @return $this
113
     */
114 146
    public function addCheck(string $checkId, &$check): self
115
    {
116 146
        $this->checks[$checkId] = &$check;
117
118 146
        return $this;
119
    }
120
121
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
122
     * @JMS\SerializedName("label")
123
     * @JMS\Type("string")
124
     * @JMS\VirtualProperty()
125
     *
126
     * @return string
127
     */
128 10
    public function getLabel()
129
    {
130 10
        return sprintf('%s(%d)', $this->name, $this->count());
131
    }
132
133
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
134
     * @JMS\SerializedName("checks")
135
     * @JMS\SkipWhenEmpty()
136
     * @JMS\Type("array<string>")
137
     * @JMS\VirtualProperty()
138
     *
139
     * @return string[]
140
     */
141 10
    public function getCheckIds(): array
142
    {
143 10
        return array_keys($this->checks);
144
    }
145
}
146