diff --git a/src/HealthCheck/HealthCheckResultDto.php b/src/HealthCheck/HealthCheckResultDto.php index 3888738d..181e1ac5 100644 --- a/src/HealthCheck/HealthCheckResultDto.php +++ b/src/HealthCheck/HealthCheckResultDto.php @@ -20,8 +20,22 @@ namespace Surfnet\Tiqr\HealthCheck; +use Tiqr_HealthCheck_Interface; + class HealthCheckResultDto { public bool $isHealthy = true; public string $errorMessage = ''; + + public static function fromHealthCheckInterface(Tiqr_HealthCheck_Interface $healthCheckInterface): self + { + $message = ''; + $isHealthy = $healthCheckInterface->healthCheck($message); + + $result = new self(); + $result->isHealthy = $isHealthy; + $result->errorMessage = $message; + + return $result; + } } diff --git a/src/Tiqr/Legacy/TiqrService.php b/src/Tiqr/Legacy/TiqrService.php index b95a9118..0da05dc3 100644 --- a/src/Tiqr/Legacy/TiqrService.php +++ b/src/Tiqr/Legacy/TiqrService.php @@ -435,11 +435,6 @@ public function stateStorageHealthCheck(): HealthCheckResultDto { assert($this->tiqrStateStorage instanceof Tiqr_HealthCheck_Interface); - $message = ''; - $result = new HealthCheckResultDto(); - $result->isHealthy = $this->tiqrStateStorage->healthCheck($message); - $result->errorMessage = $message; - - return $result; + return HealthCheckResultDto::fromHealthCheckInterface($this->tiqrStateStorage); } } diff --git a/src/Tiqr/Legacy/TiqrUserRepository.php b/src/Tiqr/Legacy/TiqrUserRepository.php index 7bdc90a8..3e33f873 100644 --- a/src/Tiqr/Legacy/TiqrUserRepository.php +++ b/src/Tiqr/Legacy/TiqrUserRepository.php @@ -39,6 +39,7 @@ public function __construct(private Tiqr_UserStorage_Interface $userStorage, pri } /** + * @throws UserNotExistsException * @see TiqrUserRepositoryInterface::createUser() */ public function createUser(string $userId, string $secret): TiqrUser @@ -54,6 +55,7 @@ public function createUser(string $userId, string $secret): TiqrUser } /** + * @throws UserNotExistsException * @see TiqrUserRepositoryInterface::createUser() */ public function getUser(string $userId): TiqrUser @@ -74,23 +76,13 @@ public function userStorageHealthCheck(): HealthCheckResultDto { assert($this->userStorage instanceof Tiqr_HealthCheck_Interface); - $message = ''; - $result = new HealthCheckResultDto(); - $result->isHealthy = $this->userStorage->healthCheck($message); - $result->errorMessage = $message; - - return $result; + return HealthCheckResultDto::fromHealthCheckInterface($this->userStorage); } - public function userSecretStorageHealthCheck(string &$message = ''): HealthCheckResultDto + public function userSecretStorageHealthCheck(): HealthCheckResultDto { assert($this->userSecretStorage instanceof Tiqr_HealthCheck_Interface); - $message = ''; - $result = new HealthCheckResultDto(); - $result->isHealthy = $this->userSecretStorage->healthCheck($message); - $result->errorMessage = $message; - - return $result; + return HealthCheckResultDto::fromHealthCheckInterface($this->userSecretStorage); } }