Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
84.21% |
16 / 19 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ConfigureCheckHelper | |
84.21% |
16 / 19 |
|
50.00% |
1 / 2 |
6.14 | |
0.00% |
0 / 1 |
| __call | |
76.92% |
10 / 13 |
|
0.00% |
0 / 1 |
5.31 | |||
| jsonSerialize | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | /** |
| 5 | * SPDX-FileCopyrightText: 2020-2024 LibreCode coop and contributors |
| 6 | * SPDX-License-Identifier: AGPL-3.0-or-later |
| 7 | */ |
| 8 | |
| 9 | namespace OCA\Libresign\Helper; |
| 10 | |
| 11 | use JsonSerializable; |
| 12 | |
| 13 | /** |
| 14 | * @method ConfigureCheckHelper setSuccessMessage(string $value) |
| 15 | * @method ConfigureCheckHelper setInfoMessage(string $value) |
| 16 | * @method ConfigureCheckHelper setErrorMessage(string $value) |
| 17 | * @method ConfigureCheckHelper setStatus(string $value) |
| 18 | * @method string getStatus() |
| 19 | * @method ConfigureCheckHelper setMessage(string $value) |
| 20 | * @method string getMessage() |
| 21 | * @method ConfigureCheckHelper setResource(string $value) |
| 22 | * @method string getResource() |
| 23 | * @method ConfigureCheckHelper setTip(string $value) |
| 24 | * @method string getTip() |
| 25 | */ |
| 26 | class ConfigureCheckHelper implements JsonSerializable { |
| 27 | use MagicGetterSetterTrait { |
| 28 | MagicGetterSetterTrait::__call as __getSet; |
| 29 | } |
| 30 | private string $status = ''; |
| 31 | private string $message = ''; |
| 32 | private string $resource = ''; |
| 33 | private string $tip = ''; |
| 34 | |
| 35 | public function __call($name, $arguments) { |
| 36 | if (!preg_match('/^set(?<status>.+)Message/', (string)$name, $matches)) { |
| 37 | return $this->__getSet($name, $arguments); |
| 38 | } |
| 39 | $status = strtolower($matches['status']); |
| 40 | if (!in_array($status, ['error', 'success', 'info'])) { |
| 41 | throw new \LogicException(sprintf('Cannot set non existing message status %s.', $status)); |
| 42 | } |
| 43 | $message = $arguments[0] ?? null; |
| 44 | if (!is_string($message)) { |
| 45 | throw new \LogicException(sprintf('Invalid error message %s.', var_export($arguments, true))); |
| 46 | } |
| 47 | if (count($arguments) > 1) { |
| 48 | throw new \LogicException(sprintf('Need to have only an argument %s.', var_export($arguments, true))); |
| 49 | } |
| 50 | $this->setStatus($status); |
| 51 | $this->setMessage($message); |
| 52 | return $this; |
| 53 | } |
| 54 | |
| 55 | #[\Override] |
| 56 | public function jsonSerialize(): array { |
| 57 | return [ |
| 58 | 'status' => $this->getStatus(), |
| 59 | 'message' => $this->getMessage(), |
| 60 | 'resource' => $this->getResource(), |
| 61 | 'tip' => $this->getTip(), |
| 62 | ]; |
| 63 | } |
| 64 | } |