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 | use ZendDiagnostics\Result\ResultInterface; |
||
| 16 | |||
| 17 | /** |
||
|
0 ignored issues
–
show
|
|||
| 18 | * @author Vladimir Turnaev <[email protected]> |
||
| 19 | */ |
||
|
0 ignored issues
–
show
|
|||
| 20 | trait CheckTrait |
||
| 21 | { |
||
| 22 | /** |
||
|
0 ignored issues
–
show
|
|||
| 23 | * @JMS\SerializedName("id") |
||
| 24 | * @JMS\Expose() |
||
| 25 | * |
||
| 26 | * @var string |
||
| 27 | */ |
||
| 28 | protected $id; |
||
| 29 | |||
| 30 | /** |
||
|
0 ignored issues
–
show
|
|||
| 31 | * @var ?string |
||
| 32 | */ |
||
| 33 | protected $label; |
||
| 34 | |||
| 35 | /** |
||
|
0 ignored issues
–
show
|
|||
| 36 | * @JMS\SerializedName("group") |
||
| 37 | * @JMS\Type("string") |
||
| 38 | * @JMS\Expose() |
||
| 39 | * |
||
| 40 | * @var string |
||
| 41 | */ |
||
| 42 | protected $group; |
||
| 43 | |||
| 44 | /** |
||
|
0 ignored issues
–
show
|
|||
| 45 | * @JMS\SerializedName("descr") |
||
| 46 | * @JMS\Type("string") |
||
| 47 | * @JMS\SkipWhenEmpty() |
||
| 48 | * @JMS\Expose() |
||
| 49 | * |
||
| 50 | * @var string? |
||
|
0 ignored issues
–
show
|
|||
| 51 | */ |
||
| 52 | protected $descr; |
||
| 53 | |||
| 54 | /** |
||
|
0 ignored issues
–
show
|
|||
| 55 | * @JMS\SerializedName("importance") |
||
| 56 | * @JMS\SkipWhenEmpty() |
||
| 57 | * @JMS\Type("string") |
||
| 58 | * @JMS\Expose() |
||
| 59 | * |
||
| 60 | * @var ?string |
||
| 61 | */ |
||
| 62 | protected $importance; |
||
| 63 | |||
| 64 | /** |
||
|
0 ignored issues
–
show
|
|||
| 65 | * @JMS\SerializedName("tags") |
||
| 66 | * @JMS\SkipWhenEmpty() |
||
| 67 | * @JMS\Type("array<string>") |
||
| 68 | * @JMS\Expose() |
||
| 69 | * |
||
| 70 | * @var string[] |
||
| 71 | */ |
||
| 72 | protected $tags = []; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Perform the actual check and return a ResultInterface. |
||
| 76 | * |
||
| 77 | * @return ResultInterface |
||
| 78 | */ |
||
| 79 | abstract public function check(); |
||
| 80 | |||
| 81 | 71 | public function getId(): string |
|
|
0 ignored issues
–
show
|
|||
| 82 | { |
||
| 83 | 71 | return $this->id; |
|
| 84 | } |
||
| 85 | |||
| 86 | 139 | public function setId(string $id) |
|
|
0 ignored issues
–
show
|
|||
| 87 | { |
||
| 88 | 139 | $this->id = $id; |
|
| 89 | 139 | } |
|
| 90 | |||
| 91 | 47 | public function getImportance() |
|
|
0 ignored issues
–
show
|
|||
| 92 | { |
||
| 93 | 47 | return $this->importance; |
|
| 94 | } |
||
| 95 | |||
| 96 | 113 | public function setImportance($importance) |
|
|
0 ignored issues
–
show
|
|||
| 97 | { |
||
| 98 | 113 | $this->importance = $importance; |
|
| 99 | 113 | } |
|
| 100 | |||
| 101 | /** |
||
|
0 ignored issues
–
show
|
|||
| 102 | * @return string[] |
||
| 103 | */ |
||
| 104 | 53 | public function getTags(): array |
|
| 105 | { |
||
| 106 | 53 | return $this->tags; |
|
| 107 | } |
||
| 108 | |||
| 109 | /** |
||
|
0 ignored issues
–
show
|
|||
| 110 | * @param string[] $tags |
||
|
0 ignored issues
–
show
|
|||
| 111 | */ |
||
|
0 ignored issues
–
show
|
|||
| 112 | 118 | public function setTags(array $tags) |
|
| 113 | { |
||
| 114 | 118 | $this->tags = $tags; |
|
| 115 | 118 | $this->tags = array_unique($this->tags); |
|
| 116 | 118 | } |
|
| 117 | |||
| 118 | /** |
||
|
0 ignored issues
–
show
|
|||
| 119 | * @param string $tag |
||
|
0 ignored issues
–
show
|
|||
| 120 | */ |
||
|
0 ignored issues
–
show
|
|||
| 121 | public function addTag($tag) |
||
| 122 | { |
||
| 123 | $this->tags[$tag]; |
||
| 124 | $this->tags = array_unique($this->tags); |
||
| 125 | } |
||
| 126 | |||
| 127 | 53 | public function getGroup(): string |
|
|
0 ignored issues
–
show
|
|||
| 128 | { |
||
| 129 | 53 | return $this->group; |
|
| 130 | } |
||
| 131 | |||
| 132 | 118 | public function setGroup(string $group) |
|
|
0 ignored issues
–
show
|
|||
| 133 | { |
||
| 134 | 118 | $this->group = $group; |
|
| 135 | 118 | } |
|
| 136 | |||
| 137 | /** |
||
|
0 ignored issues
–
show
|
|||
| 138 | * @JMS\SerializedName("label") |
||
| 139 | * @JMS\Type("string") |
||
| 140 | * @JMS\VirtualProperty() |
||
| 141 | * @JMS\Expose() |
||
| 142 | */ |
||
|
0 ignored issues
–
show
|
|||
| 143 | 59 | public function getLabel(): string |
|
| 144 | { |
||
| 145 | 59 | if (null !== $this->label) { |
|
| 146 | 13 | return $this->label; |
|
| 147 | } |
||
| 148 | |||
| 149 | 54 | return sprintf('Check %s', $this->id); |
|
| 150 | } |
||
| 151 | |||
| 152 | 118 | public function setLabel($label) |
|
|
0 ignored issues
–
show
|
|||
| 153 | { |
||
| 154 | 118 | $this->label = $label; |
|
| 155 | 118 | } |
|
| 156 | |||
| 157 | /** |
||
|
0 ignored issues
–
show
|
|||
| 158 | * @return ?string |
||
| 159 | */ |
||
| 160 | public function getDescr() |
||
| 161 | { |
||
| 162 | return $this->descr; |
||
| 163 | } |
||
| 164 | |||
| 165 | /** |
||
|
0 ignored issues
–
show
|
|||
| 166 | * @param ?string $descr |
||
|
0 ignored issues
–
show
|
|||
| 167 | */ |
||
|
0 ignored issues
–
show
|
|||
| 168 | 113 | public function setDescr(string $descr = null) |
|
| 169 | { |
||
| 170 | 113 | $this->descr = $descr; |
|
| 171 | 113 | } |
|
| 172 | |||
| 173 | 114 | public function setAdditionParams(array $data) |
|
|
0 ignored issues
–
show
|
|||
| 174 | { |
||
| 175 | 114 | if (array_key_exists('id', $data)) { |
|
| 176 | 114 | $this->setId($data['id']); |
|
| 177 | } |
||
| 178 | |||
| 179 | 114 | if (array_key_exists('group', $data)) { |
|
| 180 | 114 | $this->setGroup($data['group']); |
|
| 181 | } |
||
| 182 | |||
| 183 | 114 | if (array_key_exists('importance', $data)) { |
|
| 184 | 113 | $this->setImportance($data['importance']); |
|
| 185 | } |
||
| 186 | |||
| 187 | 114 | if (array_key_exists('tags', $data)) { |
|
| 188 | 114 | $this->setTags($data['tags']); |
|
| 189 | } |
||
| 190 | |||
| 191 | 114 | if (array_key_exists('label', $data)) { |
|
| 192 | 114 | $this->setLabel($data['label']); |
|
| 193 | } |
||
| 194 | |||
| 195 | 114 | if (array_key_exists('descr', $data)) { |
|
| 196 | 113 | $this->setDescr($data['descr']); |
|
| 197 | } |
||
| 198 | 114 | } |
|
| 199 | } |
||
| 200 |