Skip to content

Commit

Permalink
Move message formatting to the Dto itself
Browse files Browse the repository at this point in the history
  • Loading branch information
parijke committed Jun 17, 2024
1 parent 934676b commit cc53007
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
14 changes: 14 additions & 0 deletions src/HealthCheck/HealthCheckResultDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
7 changes: 1 addition & 6 deletions src/Tiqr/Legacy/TiqrService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
18 changes: 5 additions & 13 deletions src/Tiqr/Legacy/TiqrUserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -54,6 +55,7 @@ public function createUser(string $userId, string $secret): TiqrUser
}

/**
* @throws UserNotExistsException
* @see TiqrUserRepositoryInterface::createUser()
*/
public function getUser(string $userId): TiqrUser
Expand All @@ -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);
}
}

0 comments on commit cc53007

Please sign in to comment.