From 9fbc5a54c0669100dfd0f6fcc57f150b79ae48aa Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Wed, 27 Aug 2025 17:25:27 +0300 Subject: [PATCH] HP-2676: Fix issues caused by HP-2581 release: tariff view error, failing CI jobs, and SinglePrice type error --- .../Application/BillingRegistryService.php | 45 +++++++++++-------- .../PriceTypeDefinitionNotFoundException.php | 6 ++- .../TariffTypeDefinitionNotFoundException.php | 6 ++- .../behavior/BehaviorNotFoundException.php | 5 ++- .../behavior/InvalidBehaviorException.php | 5 ++- .../InvalidRepresentationException.php | 6 ++- 6 files changed, 46 insertions(+), 27 deletions(-) diff --git a/src/product/Application/BillingRegistryService.php b/src/product/Application/BillingRegistryService.php index b61b62df..8f9e53af 100644 --- a/src/product/Application/BillingRegistryService.php +++ b/src/product/Application/BillingRegistryService.php @@ -2,6 +2,7 @@ namespace hiqdev\php\billing\product\Application; +use Generator; use hiqdev\php\billing\product\AggregateInterface; use hiqdev\php\billing\product\behavior\BehaviorInterface; use hiqdev\php\billing\product\behavior\BehaviorNotFoundException; @@ -25,17 +26,17 @@ public function __construct(private readonly BillingRegistryInterface $registry) public function getRepresentationsByType(string $representationClass): array { if (!class_exists($representationClass) && !interface_exists($representationClass)) { - throw new InvalidRepresentationException("Class '$representationClass' does not exist"); + throw InvalidRepresentationException::make("Representation does not exist", [ + 'representationClass' => $representationClass, + ]); } if (class_exists($representationClass) && !is_subclass_of($representationClass, RepresentationInterface::class) ) { - throw new InvalidBehaviorException( - sprintf( - 'Representation class "%s" does not implement RepresentationInterface', - $representationClass, - ) + throw InvalidBehaviorException::make('Representation class does not implement RepresentationInterface', [ + 'representationClass' => $representationClass, + ] ); } @@ -59,20 +60,25 @@ public function getTariffTypeDefinitionByTariffName(string $tariffName): TariffT } } - throw new TariffTypeDefinitionNotFoundException('Tariff type definition was not found'); + throw TariffTypeDefinitionNotFoundException::make('TariffTypeDefinition was not found', [ + 'tariffName' => $tariffName, + ]); } public function getBehavior(string $type, string $behaviorClassWrapper): BehaviorInterface { if (!class_exists($behaviorClassWrapper)) { - throw new InvalidBehaviorException( - sprintf('Behavior class "%s" does not exist', $behaviorClassWrapper) + throw InvalidBehaviorException::make( 'Behavior class does not exist', [ + 'behavior' => $behaviorClassWrapper, + ] ); } if (!is_subclass_of($behaviorClassWrapper, BehaviorInterface::class)) { - throw new InvalidBehaviorException( - sprintf('Behavior class "%s" does not implement BehaviorInterface', $behaviorClassWrapper) + throw InvalidBehaviorException::make( + 'Behavior class does not implement BehaviorInterface', [ + 'behavior' => $behaviorClassWrapper, + ] ); } @@ -88,8 +94,10 @@ public function getBehavior(string $type, string $behaviorClassWrapper): Behavio } } - throw new BehaviorNotFoundException( - sprintf('Behavior of class "%s" not found for type "%s"', $behaviorClassWrapper, $type), + throw BehaviorNotFoundException::make('Behavior was not found', [ + 'behavior' => $behaviorClassWrapper, + 'type' => $type, + ], ); } @@ -111,7 +119,7 @@ private function findBehaviorInPriceType( return null; } - public function getBehaviors(string $behaviorClassWrapper): \Generator + public function getBehaviors(string $behaviorClassWrapper): Generator { foreach ($this->registry->getTariffTypeDefinitions() as $tariffTypeDefinition) { foreach ($tariffTypeDefinition->withBehaviors() as $behavior) { @@ -145,13 +153,12 @@ public function getPriceTypeDefinitionByPriceTypeName(string $typeName): PriceTy } } - throw new PriceTypeDefinitionNotFoundException(sprintf( - 'PriceTypeDefinition was not found for %s type', - $typeName, - )); + throw PriceTypeDefinitionNotFoundException::make('PriceTypeDefinition was not found', [ + 'type' => $typeName, + ]); } - public function findPriceTypeDefinitionsByBehavior(string $behaviorClassWrapper): \Generator + public function findPriceTypeDefinitionsByBehavior(string $behaviorClassWrapper): Generator { foreach ($this->registry->priceTypes() as $priceTypeDefinition) { if ($priceTypeDefinition->hasBehavior($behaviorClassWrapper)) { diff --git a/src/product/Exception/PriceTypeDefinitionNotFoundException.php b/src/product/Exception/PriceTypeDefinitionNotFoundException.php index ec0d8ef2..e6edb4c4 100644 --- a/src/product/Exception/PriceTypeDefinitionNotFoundException.php +++ b/src/product/Exception/PriceTypeDefinitionNotFoundException.php @@ -2,9 +2,11 @@ namespace hiqdev\php\billing\product\Exception; +use hidev\exception\HasContext; +use hidev\exception\HasContextInterface; use hiqdev\php\billing\Exception\RuntimeException; -class PriceTypeDefinitionNotFoundException extends RuntimeException +class PriceTypeDefinitionNotFoundException extends RuntimeException implements HasContextInterface { - + use HasContext; } diff --git a/src/product/Exception/TariffTypeDefinitionNotFoundException.php b/src/product/Exception/TariffTypeDefinitionNotFoundException.php index aff28a38..5692a60e 100644 --- a/src/product/Exception/TariffTypeDefinitionNotFoundException.php +++ b/src/product/Exception/TariffTypeDefinitionNotFoundException.php @@ -2,9 +2,11 @@ namespace hiqdev\php\billing\product\Exception; +use hidev\exception\HasContext; +use hidev\exception\HasContextInterface; use hiqdev\php\billing\Exception\RuntimeException; -class TariffTypeDefinitionNotFoundException extends RuntimeException +class TariffTypeDefinitionNotFoundException extends RuntimeException implements HasContextInterface { - + use HasContext; } diff --git a/src/product/behavior/BehaviorNotFoundException.php b/src/product/behavior/BehaviorNotFoundException.php index bf8fffc7..6fc9b7df 100644 --- a/src/product/behavior/BehaviorNotFoundException.php +++ b/src/product/behavior/BehaviorNotFoundException.php @@ -2,8 +2,11 @@ namespace hiqdev\php\billing\product\behavior; +use hidev\exception\HasContext; +use hidev\exception\HasContextInterface; use hiqdev\php\billing\Exception\RuntimeException; -class BehaviorNotFoundException extends RuntimeException +class BehaviorNotFoundException extends RuntimeException implements HasContextInterface { + use HasContext; } diff --git a/src/product/behavior/InvalidBehaviorException.php b/src/product/behavior/InvalidBehaviorException.php index 82ed5868..3f209b2a 100644 --- a/src/product/behavior/InvalidBehaviorException.php +++ b/src/product/behavior/InvalidBehaviorException.php @@ -2,8 +2,11 @@ namespace hiqdev\php\billing\product\behavior; +use hidev\exception\HasContext; +use hidev\exception\HasContextInterface; use InvalidArgumentException; -class InvalidBehaviorException extends InvalidArgumentException +class InvalidBehaviorException extends InvalidArgumentException implements HasContextInterface { + use HasContext; } diff --git a/src/product/invoice/InvalidRepresentationException.php b/src/product/invoice/InvalidRepresentationException.php index 605deb94..89a66fb8 100644 --- a/src/product/invoice/InvalidRepresentationException.php +++ b/src/product/invoice/InvalidRepresentationException.php @@ -2,9 +2,11 @@ namespace hiqdev\php\billing\product\invoice; +use hidev\exception\HasContext; +use hidev\exception\HasContextInterface; use InvalidArgumentException; -class InvalidRepresentationException extends InvalidArgumentException +class InvalidRepresentationException extends InvalidArgumentException implements HasContextInterface { - + use HasContext; }