Skip to content

Commit e28267a

Browse files
HP-2676: Fix issues caused by HP-2581 release: tariff view error, failing CI jobs, and SinglePrice type error (#105)
1 parent e713078 commit e28267a

File tree

6 files changed

+46
-27
lines changed

6 files changed

+46
-27
lines changed

src/product/Application/BillingRegistryService.php

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace hiqdev\php\billing\product\Application;
44

5+
use Generator;
56
use hiqdev\php\billing\product\AggregateInterface;
67
use hiqdev\php\billing\product\behavior\BehaviorInterface;
78
use hiqdev\php\billing\product\behavior\BehaviorNotFoundException;
@@ -25,17 +26,17 @@ public function __construct(private readonly BillingRegistryInterface $registry)
2526
public function getRepresentationsByType(string $representationClass): array
2627
{
2728
if (!class_exists($representationClass) && !interface_exists($representationClass)) {
28-
throw new InvalidRepresentationException("Class '$representationClass' does not exist");
29+
throw InvalidRepresentationException::make("Representation does not exist", [
30+
'representationClass' => $representationClass,
31+
]);
2932
}
3033

3134
if (class_exists($representationClass)
3235
&& !is_subclass_of($representationClass, RepresentationInterface::class)
3336
) {
34-
throw new InvalidBehaviorException(
35-
sprintf(
36-
'Representation class "%s" does not implement RepresentationInterface',
37-
$representationClass,
38-
)
37+
throw InvalidBehaviorException::make('Representation class does not implement RepresentationInterface', [
38+
'representationClass' => $representationClass,
39+
]
3940
);
4041
}
4142

@@ -59,20 +60,25 @@ public function getTariffTypeDefinitionByTariffName(string $tariffName): TariffT
5960
}
6061
}
6162

62-
throw new TariffTypeDefinitionNotFoundException('Tariff type definition was not found');
63+
throw TariffTypeDefinitionNotFoundException::make('TariffTypeDefinition was not found', [
64+
'tariffName' => $tariffName,
65+
]);
6366
}
6467

6568
public function getBehavior(string $type, string $behaviorClassWrapper): BehaviorInterface
6669
{
6770
if (!class_exists($behaviorClassWrapper)) {
68-
throw new InvalidBehaviorException(
69-
sprintf('Behavior class "%s" does not exist', $behaviorClassWrapper)
71+
throw InvalidBehaviorException::make( 'Behavior class does not exist', [
72+
'behavior' => $behaviorClassWrapper,
73+
]
7074
);
7175
}
7276

7377
if (!is_subclass_of($behaviorClassWrapper, BehaviorInterface::class)) {
74-
throw new InvalidBehaviorException(
75-
sprintf('Behavior class "%s" does not implement BehaviorInterface', $behaviorClassWrapper)
78+
throw InvalidBehaviorException::make(
79+
'Behavior class does not implement BehaviorInterface', [
80+
'behavior' => $behaviorClassWrapper,
81+
]
7682
);
7783
}
7884

@@ -88,8 +94,10 @@ public function getBehavior(string $type, string $behaviorClassWrapper): Behavio
8894
}
8995
}
9096

91-
throw new BehaviorNotFoundException(
92-
sprintf('Behavior of class "%s" not found for type "%s"', $behaviorClassWrapper, $type),
97+
throw BehaviorNotFoundException::make('Behavior was not found', [
98+
'behavior' => $behaviorClassWrapper,
99+
'type' => $type,
100+
],
93101
);
94102
}
95103

@@ -111,7 +119,7 @@ private function findBehaviorInPriceType(
111119
return null;
112120
}
113121

114-
public function getBehaviors(string $behaviorClassWrapper): \Generator
122+
public function getBehaviors(string $behaviorClassWrapper): Generator
115123
{
116124
foreach ($this->registry->getTariffTypeDefinitions() as $tariffTypeDefinition) {
117125
foreach ($tariffTypeDefinition->withBehaviors() as $behavior) {
@@ -145,13 +153,12 @@ public function getPriceTypeDefinitionByPriceTypeName(string $typeName): PriceTy
145153
}
146154
}
147155

148-
throw new PriceTypeDefinitionNotFoundException(sprintf(
149-
'PriceTypeDefinition was not found for %s type',
150-
$typeName,
151-
));
156+
throw PriceTypeDefinitionNotFoundException::make('PriceTypeDefinition was not found', [
157+
'type' => $typeName,
158+
]);
152159
}
153160

154-
public function findPriceTypeDefinitionsByBehavior(string $behaviorClassWrapper): \Generator
161+
public function findPriceTypeDefinitionsByBehavior(string $behaviorClassWrapper): Generator
155162
{
156163
foreach ($this->registry->priceTypes() as $priceTypeDefinition) {
157164
if ($priceTypeDefinition->hasBehavior($behaviorClassWrapper)) {

src/product/Exception/PriceTypeDefinitionNotFoundException.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
namespace hiqdev\php\billing\product\Exception;
44

5+
use hidev\exception\HasContext;
6+
use hidev\exception\HasContextInterface;
57
use hiqdev\php\billing\Exception\RuntimeException;
68

7-
class PriceTypeDefinitionNotFoundException extends RuntimeException
9+
class PriceTypeDefinitionNotFoundException extends RuntimeException implements HasContextInterface
810
{
9-
11+
use HasContext;
1012
}

src/product/Exception/TariffTypeDefinitionNotFoundException.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
namespace hiqdev\php\billing\product\Exception;
44

5+
use hidev\exception\HasContext;
6+
use hidev\exception\HasContextInterface;
57
use hiqdev\php\billing\Exception\RuntimeException;
68

7-
class TariffTypeDefinitionNotFoundException extends RuntimeException
9+
class TariffTypeDefinitionNotFoundException extends RuntimeException implements HasContextInterface
810
{
9-
11+
use HasContext;
1012
}

src/product/behavior/BehaviorNotFoundException.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
namespace hiqdev\php\billing\product\behavior;
44

5+
use hidev\exception\HasContext;
6+
use hidev\exception\HasContextInterface;
57
use hiqdev\php\billing\Exception\RuntimeException;
68

7-
class BehaviorNotFoundException extends RuntimeException
9+
class BehaviorNotFoundException extends RuntimeException implements HasContextInterface
810
{
11+
use HasContext;
912
}

src/product/behavior/InvalidBehaviorException.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
namespace hiqdev\php\billing\product\behavior;
44

5+
use hidev\exception\HasContext;
6+
use hidev\exception\HasContextInterface;
57
use InvalidArgumentException;
68

7-
class InvalidBehaviorException extends InvalidArgumentException
9+
class InvalidBehaviorException extends InvalidArgumentException implements HasContextInterface
810
{
11+
use HasContext;
912
}

src/product/invoice/InvalidRepresentationException.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
namespace hiqdev\php\billing\product\invoice;
44

5+
use hidev\exception\HasContext;
6+
use hidev\exception\HasContextInterface;
57
use InvalidArgumentException;
68

7-
class InvalidRepresentationException extends InvalidArgumentException
9+
class InvalidRepresentationException extends InvalidArgumentException implements HasContextInterface
810
{
9-
11+
use HasContext;
1012
}

0 commit comments

Comments
 (0)