diff --git a/src/Domain/Customer/Service/CustomerUpdater.php b/src/Domain/Customer/Service/CustomerUpdater.php index f01d9dce9..3b1d9bbd7 100644 --- a/src/Domain/Customer/Service/CustomerUpdater.php +++ b/src/Domain/Customer/Service/CustomerUpdater.php @@ -4,6 +4,7 @@ use App\Domain\Customer\Repository\CustomerRepository; use App\Factory\LoggerFactory; +use DomainException; use Psr\Log\LoggerInterface; final class CustomerUpdater @@ -29,7 +30,7 @@ public function __construct( public function updateCustomer(int $customerId, array $data): void { // Input validation - $this->customerValidator->validateCustomerUpdate($customerId, $data); + $this->validateCustomerUpdate($customerId, $data); // Update the row $this->repository->updateCustomer($customerId, $data); @@ -37,4 +38,13 @@ public function updateCustomer(int $customerId, array $data): void // Logging $this->logger->info(sprintf('Customer updated successfully: %s', $customerId)); } + + public function validateCustomerUpdate(int $customerId, array $data): void + { + if (!$this->repository->existsCustomerId($customerId)) { + throw new DomainException(sprintf('Customer not found: %s', $customerId)); + } + + $this->customerValidator->validateCustomer($data); + } } diff --git a/src/Domain/Customer/Service/CustomerValidator.php b/src/Domain/Customer/Service/CustomerValidator.php index 005bd3f6b..19defa779 100644 --- a/src/Domain/Customer/Service/CustomerValidator.php +++ b/src/Domain/Customer/Service/CustomerValidator.php @@ -2,29 +2,11 @@ namespace App\Domain\Customer\Service; -use App\Domain\Customer\Repository\CustomerRepository; use App\Support\Validation\ValidationException; use Cake\Validation\Validator; -use DomainException; final class CustomerValidator { - private CustomerRepository $repository; - - public function __construct(CustomerRepository $repository) - { - $this->repository = $repository; - } - - public function validateCustomerUpdate(int $customerId, array $data): void - { - if (!$this->repository->existsCustomerId($customerId)) { - throw new DomainException(sprintf('Customer not found: %s', $customerId)); - } - - $this->validateCustomer($data); - } - public function validateCustomer(array $data): void { $validator = new Validator();