turnaev /
monitor-bundle
| 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
Loading history...
|
|||
| 11 | |||
| 12 | namespace Tvi\MonitorBundle\Check; |
||
| 13 | |||
| 14 | use JMS\Serializer\Annotation as JMS; |
||
| 15 | |||
| 16 | /** |
||
|
0 ignored issues
–
show
|
|||
| 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
|
|||
| 25 | class Group implements \ArrayAccess, \Iterator, \Countable |
||
| 26 | { |
||
| 27 | use CheckArraybleTrait; |
||
| 28 | |||
| 29 | /** |
||
|
0 ignored issues
–
show
|
|||
| 30 | * @JMS\SerializedName("id") |
||
| 31 | * @JMS\Type("string") |
||
| 32 | * |
||
| 33 | * @var string |
||
| 34 | */ |
||
| 35 | protected $id; |
||
| 36 | |||
| 37 | /** |
||
|
0 ignored issues
–
show
|
|||
| 38 | * @JMS\SerializedName("name") |
||
| 39 | * @JMS\Type("string") |
||
| 40 | * |
||
| 41 | * @var string |
||
| 42 | */ |
||
| 43 | protected $name; |
||
| 44 | |||
| 45 | /** |
||
|
0 ignored issues
–
show
|
|||
| 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
|
|||
| 55 | * Group constructor. |
||
| 56 | * |
||
| 57 | * @param ?string $name |
||
|
0 ignored issues
–
show
|
|||
| 58 | * @param ?string $descr |
||
|
0 ignored issues
–
show
|
|||
| 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
|
|||
| 68 | { |
||
| 69 | 133 | return $this->id; |
|
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
|
0 ignored issues
–
show
|
|||
| 73 | * @param mixed $name |
||
|
0 ignored issues
–
show
|
|||
| 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
|
|||
| 85 | { |
||
| 86 | 133 | return $this->name; |
|
| 87 | } |
||
| 88 | |||
| 89 | /** |
||
|
0 ignored issues
–
show
|
|||
| 90 | * @param ?string $descr |
||
|
0 ignored issues
–
show
|
|||
| 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
|
|||
| 102 | * @return null|string |
||
| 103 | */ |
||
| 104 | 1 | public function getDescr() |
|
| 105 | { |
||
| 106 | 1 | return $this->descr; |
|
| 107 | } |
||
| 108 | |||
| 109 | /** |
||
|
0 ignored issues
–
show
|
|||
| 110 | * @param CheckInterface|Proxy $check |
||
|
0 ignored issues
–
show
|
|||
| 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
|
|||
| 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
|
|||
| 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 |