diff --git a/src/Application/Security/Exceptions/ClientNameAlreadyExistsException.php b/src/Application/Security/Exceptions/ClientNameAlreadyExistsException.php index 008c228..15f616b 100644 --- a/src/Application/Security/Exceptions/ClientNameAlreadyExistsException.php +++ b/src/Application/Security/Exceptions/ClientNameAlreadyExistsException.php @@ -4,10 +4,12 @@ declare(strict_types=1); namespace Application\Security\Exceptions; +use Application\Security\Models\ValueObjects\ClientName; + final class ClientNameAlreadyExistsException extends \DomainException { - public static function forName(string $name): self + public static function forName(ClientName $name): self { - return new self("A client with the name '{$name}' (or similar) already exists."); + return new self("A client with the name '{$name->value}' (or similar) already exists."); } } diff --git a/src/Application/Security/Exceptions/ClientNotFoundException.php b/src/Application/Security/Exceptions/ClientNotFoundException.php index d4dd1ac..580ac45 100644 --- a/src/Application/Security/Exceptions/ClientNotFoundException.php +++ b/src/Application/Security/Exceptions/ClientNotFoundException.php @@ -4,12 +4,14 @@ declare(strict_types=1); namespace Application\Security\Exceptions; +use Application\Security\Models\ValueObjects\ClientIdentifier; +use Application\Security\Models\ValueObjects\Entities\ClientId; use Shared\DDD\Exception\NotFoundException; final class ClientNotFoundException extends NotFoundException { - public static function forClient(string $clientId): self + public static function forClient(ClientId | ClientIdentifier $clientId): self { - return new self("Client '{$clientId}' not found."); + return new self("Client '{$clientId->value}' not found."); } } diff --git a/src/Application/Security/Usecases/CreateClient/CreateClient.php b/src/Application/Security/Usecases/CreateClient/CreateClient.php index 2f03d39..233845a 100644 --- a/src/Application/Security/Usecases/CreateClient/CreateClient.php +++ b/src/Application/Security/Usecases/CreateClient/CreateClient.php @@ -32,7 +32,7 @@ final readonly class CreateClient implements Usecase Assert::isInstanceOf($input, Input::class); if ($this->clientRepository->existsByName($input->name)) { - throw ClientNameAlreadyExistsException::forName($input->name->value); + throw ClientNameAlreadyExistsException::forName($input->name); } $clientId = $input->clientId ?? new ClientId(Uuid::uuid7()); diff --git a/src/Application/Security/Usecases/RegenerateClientSecret/RegenerateClientSecret.php b/src/Application/Security/Usecases/RegenerateClientSecret/RegenerateClientSecret.php index 0328372..fc21382 100644 --- a/src/Application/Security/Usecases/RegenerateClientSecret/RegenerateClientSecret.php +++ b/src/Application/Security/Usecases/RegenerateClientSecret/RegenerateClientSecret.php @@ -27,7 +27,7 @@ final readonly class RegenerateClientSecret implements Usecase { Assert::isInstanceOf($input, Input::class); - $client = $this->clientRepository->find($input->clientId) ?? throw ClientNotFoundException::forClient($input->clientId->value); + $client = $this->clientRepository->find($input->clientId) ?? throw ClientNotFoundException::forClient($input->clientId); $newSecret = $this->credentialGenerator->generateSecret(); $client->regenerateSecret($newSecret); diff --git a/src/Application/Security/Usecases/ToggleClientStatus/SetClientStatus.php b/src/Application/Security/Usecases/ToggleClientStatus/SetClientStatus.php index 5cdbd16..c733341 100644 --- a/src/Application/Security/Usecases/ToggleClientStatus/SetClientStatus.php +++ b/src/Application/Security/Usecases/ToggleClientStatus/SetClientStatus.php @@ -27,7 +27,7 @@ final readonly class SetClientStatus implements Usecase Assert::isInstanceOf($input, Input::class); $client = $this->clientRepository->findByIdentifier($input->clientIdentifier) - ?? throw ClientNotFoundException::forClient($input->clientIdentifier->value); + ?? throw ClientNotFoundException::forClient($input->clientIdentifier); $changed = $client->isActive !== $input->desiredStatus; $isActive = $client->setActive($input->desiredStatus); diff --git a/src/Infra/Adapters/Repositories/ApiClientRepository.php b/src/Infra/Adapters/Repositories/ApiClientRepository.php index d463194..a9aae56 100644 --- a/src/Infra/Adapters/Repositories/ApiClientRepository.php +++ b/src/Infra/Adapters/Repositories/ApiClientRepository.php @@ -116,7 +116,7 @@ final class ApiClientRepository implements ClientDirectory, ClientRepository { $deleted = ApiClient::query()->where('id', $client->id->value)->delete(); if ($deleted === 0) { - throw ClientNotFoundException::forClient($client->id->value); + throw ClientNotFoundException::forClient($client->id); } } diff --git a/src/Infra/Adapters/Repositories/InMemoryClientRepository.php b/src/Infra/Adapters/Repositories/InMemoryClientRepository.php index 5f38677..5402218 100644 --- a/src/Infra/Adapters/Repositories/InMemoryClientRepository.php +++ b/src/Infra/Adapters/Repositories/InMemoryClientRepository.php @@ -50,7 +50,7 @@ final class InMemoryClientRepository implements ClientDirectory, ClientRepositor public function delete(Client $client): void { if (! isset($this->clients[$client->id->value])) { - throw ClientNotFoundException::forClient($client->id->value); + throw ClientNotFoundException::forClient($client->id); } unset($this->clients[$client->id->value]); diff --git a/src/Presentation/Console/Commands/CreateClientCommand.php b/src/Presentation/Console/Commands/CreateClientCommand.php index 2ee8c59..0822402 100644 --- a/src/Presentation/Console/Commands/CreateClientCommand.php +++ b/src/Presentation/Console/Commands/CreateClientCommand.php @@ -81,7 +81,7 @@ final class CreateClientCommand extends Command $clientName = new ClientName($trimmed); if ($this->clientRepository->existsByName($clientName)) { - return ClientNameAlreadyExistsException::forName($trimmed)->getMessage(); + return ClientNameAlreadyExistsException::forName($clientName)->getMessage(); } } catch (\InvalidArgumentException $e) { return $e->getMessage();