22
33namespace hiqdev \php \billing \product \Application ;
44
5+ use Generator ;
56use hiqdev \php \billing \product \AggregateInterface ;
67use hiqdev \php \billing \product \behavior \BehaviorInterface ;
78use 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 )) {
0 commit comments