From a3f444a6701361a99c47c853176f4517ea03905a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Mon, 14 Sep 2026 09:40:24 +0200 Subject: [PATCH] refactor: DTO and VO updates --- src/Lib/ApiConfig.php | 9 +++++++-- src/Lib/ApiDto/Dto/Brand.php | 2 +- src/Lib/ApiDto/Dto/Inco/Allergen.php | 2 +- src/Lib/ApiDto/Dto/Inco/Ingredients.php | 2 +- src/Lib/ApiDto/Dto/Inco/StorageCondition.php | 2 +- src/Lib/ApiSorter/AbstractSorter.php | 2 +- 6 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Lib/ApiConfig.php b/src/Lib/ApiConfig.php index aa6b228..73d5180 100644 --- a/src/Lib/ApiConfig.php +++ b/src/Lib/ApiConfig.php @@ -5,6 +5,8 @@ declare(strict_types=1); namespace Uwil\ArcadiaApiPhpClient\Lib; use Psr\Http\Message\UriInterface; +use Uwil\ArcadiaApiPhpClient\Auth\ClientIdentifier; +use Uwil\ArcadiaApiPhpClient\Auth\ClientSecret; readonly class ApiConfig { @@ -12,13 +14,16 @@ readonly class ApiConfig #[\SensitiveParameter] public readonly UriInterface $endpoint, #[\SensitiveParameter] - public readonly string $apiKey, + public readonly ClientIdentifier $apiKey, #[\SensitiveParameter] - public readonly string $secret, + public readonly ClientSecret $secret, public readonly float $curlTimeOut = 20.0, public readonly int $maxRetries = 0, public readonly int $retryDelayMs = 500, ) { + if ($curlTimeOut < 0) { + throw new \InvalidArgumentException('curlTimeOut must be non-negative'); + } if ($maxRetries < 0) { throw new \InvalidArgumentException('maxRetries must be non-negative'); } diff --git a/src/Lib/ApiDto/Dto/Brand.php b/src/Lib/ApiDto/Dto/Brand.php index 119d7d5..4263cfa 100644 --- a/src/Lib/ApiDto/Dto/Brand.php +++ b/src/Lib/ApiDto/Dto/Brand.php @@ -14,7 +14,7 @@ final readonly class Brand implements Dto public readonly BrandCode $code, public readonly string $label ) { - if (empty(trim($label))) { + if (empty(mb_trim($label))) { throw new DomainException( "Invalid label '{$label}' should not be empty" ); diff --git a/src/Lib/ApiDto/Dto/Inco/Allergen.php b/src/Lib/ApiDto/Dto/Inco/Allergen.php index d61520d..c30d49d 100644 --- a/src/Lib/ApiDto/Dto/Inco/Allergen.php +++ b/src/Lib/ApiDto/Dto/Inco/Allergen.php @@ -19,7 +19,7 @@ final readonly class Allergen implements Dto ); } - if (empty(trim($label))) { + if (empty(mb_trim($label))) { throw new DomainException( "Invalid label '{$label}' should not be empty" ); diff --git a/src/Lib/ApiDto/Dto/Inco/Ingredients.php b/src/Lib/ApiDto/Dto/Inco/Ingredients.php index 78bb445..cbf99e9 100644 --- a/src/Lib/ApiDto/Dto/Inco/Ingredients.php +++ b/src/Lib/ApiDto/Dto/Inco/Ingredients.php @@ -39,7 +39,7 @@ final readonly class Ingredients implements Dto ); } - if (empty(trim($line))) { + if (empty(mb_trim($line))) { throw new DomainException( "Invalid ingredient at group '{$key}', index '{$i}': string should not be empty" ); diff --git a/src/Lib/ApiDto/Dto/Inco/StorageCondition.php b/src/Lib/ApiDto/Dto/Inco/StorageCondition.php index bddfa4a..abade13 100644 --- a/src/Lib/ApiDto/Dto/Inco/StorageCondition.php +++ b/src/Lib/ApiDto/Dto/Inco/StorageCondition.php @@ -17,7 +17,7 @@ final readonly class StorageCondition implements Dto public function __construct( public readonly string $instructions, ) { - if (empty(trim($this->instructions))) { + if (empty(mb_trim($this->instructions))) { throw new DomainException( 'Invalid instructions: must not be empty' ); diff --git a/src/Lib/ApiSorter/AbstractSorter.php b/src/Lib/ApiSorter/AbstractSorter.php index 696a665..9a7340b 100644 --- a/src/Lib/ApiSorter/AbstractSorter.php +++ b/src/Lib/ApiSorter/AbstractSorter.php @@ -13,7 +13,7 @@ final readonly class AbstractSorter public string $sortBy, public Direction $direction ) { - if (empty(trim($sortBy))) { + if (empty(mb_trim($sortBy))) { throw new DomainException('Sort by cannot be empty'); } }