From 0aff5ab67825b0589caa66611eeeb69a16a5dbfa Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Sun, 10 Aug 2025 14:26:43 +0300 Subject: [PATCH 01/11] HP-2496: Extend TariffTypeDefinition with findBehaviorByClass method --- src/product/TariffTypeDefinition.php | 31 ++------------ src/product/TariffTypeDefinitionInterface.php | 2 - src/product/behavior/BehaviorRegistry.php | 39 ++++++++++++++++++ .../behavior/HasBehaviorsInterface.php | 3 +- .../behavior/PriceTypeBehaviourRegistry.php | 40 +++++++++++++++++++ .../behavior/TariffTypeBehaviorRegistry.php | 30 ++------------ src/product/price/PriceTypeDefinition.php | 37 +++++------------ .../TariffTypeBehaviorRegistryTest.php | 4 +- 8 files changed, 101 insertions(+), 85 deletions(-) create mode 100644 src/product/behavior/BehaviorRegistry.php create mode 100644 src/product/behavior/PriceTypeBehaviourRegistry.php diff --git a/src/product/TariffTypeDefinition.php b/src/product/TariffTypeDefinition.php index 789c6b7d..730517eb 100644 --- a/src/product/TariffTypeDefinition.php +++ b/src/product/TariffTypeDefinition.php @@ -2,19 +2,14 @@ namespace hiqdev\php\billing\product; -use Google\Service\TPU; use hiqdev\php\billing\product\behavior\BehaviorCollectionInterface; -use hiqdev\php\billing\product\behavior\BehaviorInterface; -use hiqdev\php\billing\product\behavior\BehaviorTariffTypeCollection; use hiqdev\php\billing\product\behavior\TariffTypeBehaviorRegistry; use hiqdev\php\billing\product\Domain\Model\TariffTypeInterface; use hiqdev\php\billing\product\Exception\ProductNotDefinedException; -use hiqdev\php\billing\product\price\PriceTypeDefinition; use hiqdev\php\billing\product\price\PriceTypeDefinitionCollection; -use hiqdev\php\billing\product\price\PriceTypeDefinitionCollectionInterface; use hiqdev\php\billing\product\price\PriceTypeDefinitionFactory; -use hiqdev\php\billing\product\price\PriceTypeDefinitionInterface; use hiqdev\php\billing\product\trait\HasLock; +use LogicException; /** * @template TPriceTypeDefinitionCollection of PriceTypeDefinitionCollection @@ -89,24 +84,6 @@ public function withPrices() return $this->prices; } - public function findPricesByTypeName(string $typeName): ?array - { - $prices = null; - $this->ensureNotLocked(); - - foreach ($this->prices as $price) { - if ($this->matchesPriceType($price, $typeName)) { - $prices[] = $price; - } - } - return $prices; - } - - private function matchesPriceType(PriceTypeDefinitionInterface $price, string $typeName): bool - { - return str_ends_with($price->type()->getName(), ",$typeName"); - } - /** * @return BehaviorCollectionInterface * @psalm-suppress ImplementedReturnTypeMismatch @@ -117,7 +94,7 @@ public function withBehaviors() { $this->ensureNotLocked(); - return $this->tariffTypeBehaviorRegistry->getBehaviors(); + return $this->tariffTypeBehaviorRegistry->withBehaviors(); } public function hasBehavior(string $behaviorClassName): bool @@ -125,7 +102,7 @@ public function hasBehavior(string $behaviorClassName): bool return $this->tariffTypeBehaviorRegistry->hasBehavior($behaviorClassName); } - public function findBehaviorByClass(string $class): ?BehaviorInterface + public function findBehaviorByClass(string $class) { return $this->tariffTypeBehaviorRegistry->findBehaviorByClass($class); } @@ -136,7 +113,7 @@ public function end(): TariffTypeDefinitionInterface // Validate prices configuration is complete if ($this->prices->count() === 0) { - throw new \LogicException('At least one price type must be defined'); + throw new LogicException('At least one price type must be defined'); } return $this; diff --git a/src/product/TariffTypeDefinitionInterface.php b/src/product/TariffTypeDefinitionInterface.php index b39bd1fa..f6e7a847 100644 --- a/src/product/TariffTypeDefinitionInterface.php +++ b/src/product/TariffTypeDefinitionInterface.php @@ -37,6 +37,4 @@ public function setPricesSuggester(string $suggesterClass): static; public function withPrices(); public function end(); - - public function findPricesByTypeName(string $typeName): ?array; } diff --git a/src/product/behavior/BehaviorRegistry.php b/src/product/behavior/BehaviorRegistry.php new file mode 100644 index 00000000..2364209c --- /dev/null +++ b/src/product/behavior/BehaviorRegistry.php @@ -0,0 +1,39 @@ +getBehaviorCollection() as $behavior) { + if ($behavior instanceof $behaviorClassName) { + return true; + } + } + + return false; + } + + public function findBehaviorByClass(string $class) + { + foreach ($this->withBehaviors() as $behavior) { + if ($behavior instanceof $class) { + return $behavior; + } + } + + return null; + } + + public function lock(): void + { + $this->getBehaviorCollection()->lock(); + } +} diff --git a/src/product/behavior/HasBehaviorsInterface.php b/src/product/behavior/HasBehaviorsInterface.php index a71a3661..007ca68c 100644 --- a/src/product/behavior/HasBehaviorsInterface.php +++ b/src/product/behavior/HasBehaviorsInterface.php @@ -2,7 +2,6 @@ namespace hiqdev\php\billing\product\behavior; -use hiqdev\php\billing\product\invoice\RepresentationCollection; use hiqdev\php\billing\product\price\PriceTypeDefinitionInterface; use hiqdev\php\billing\product\TariffTypeDefinitionInterface; @@ -19,5 +18,5 @@ public function withBehaviors(); public function hasBehavior(string $behaviorClassName): bool; - public function findBehaviorByClass(string $class): ?BehaviorInterface; + public function findBehaviorByClass(string $class); } diff --git a/src/product/behavior/PriceTypeBehaviourRegistry.php b/src/product/behavior/PriceTypeBehaviourRegistry.php new file mode 100644 index 00000000..dc9eb9c5 --- /dev/null +++ b/src/product/behavior/PriceTypeBehaviourRegistry.php @@ -0,0 +1,40 @@ + + */ + private BehaviorPriceTypeDefinitionCollection $behaviorCollection; + + /** + * @psalm-param T $tariffTypeDefinition + */ + public function __construct(PriceTypeDefinitionInterface $tariffTypeDefinition, TariffTypeInterface $tariffType) + { + $this->behaviorCollection = new BehaviorPriceTypeDefinitionCollection($tariffTypeDefinition, $tariffType); + } + + /** + * @return BehaviorPriceTypeDefinitionCollection + */ + public function withBehaviors(): BehaviorPriceTypeDefinitionCollection + { + return $this->behaviorCollection; + } + + protected function getBehaviorCollection(): BehaviorCollectionInterface + { + return $this->behaviorCollection; + } +} diff --git a/src/product/behavior/TariffTypeBehaviorRegistry.php b/src/product/behavior/TariffTypeBehaviorRegistry.php index f2095db9..1644bb16 100644 --- a/src/product/behavior/TariffTypeBehaviorRegistry.php +++ b/src/product/behavior/TariffTypeBehaviorRegistry.php @@ -26,7 +26,7 @@ * * @template-covariant T of TariffTypeDefinitionInterface */ -final class TariffTypeBehaviorRegistry implements HasLockInterface +final class TariffTypeBehaviorRegistry extends BehaviorRegistry { /** * @var BehaviorTariffTypeCollection @@ -44,35 +44,13 @@ public function __construct(TariffTypeDefinitionInterface $tariffTypeDefinition, /** * @return BehaviorTariffTypeCollection */ - public function getBehaviors(): BehaviorTariffTypeCollection + public function withBehaviors(): BehaviorTariffTypeCollection { return $this->behaviorCollection; } - public function hasBehavior(string $behaviorClassName): bool + protected function getBehaviorCollection(): BehaviorCollectionInterface { - foreach ($this->behaviorCollection as $behavior) { - if ($behavior instanceof $behaviorClassName) { - return true; - } - } - - return false; - } - - public function findBehaviorByClass(string $class): ?BehaviorInterface - { - foreach ($this->getBehaviors() as $behavior) { - if ($behavior instanceof $class) { - return $behavior; - } - } - - return null; - } - - public function lock(): void - { - $this->behaviorCollection->lock(); + return $this->behaviorCollection; } } diff --git a/src/product/price/PriceTypeDefinition.php b/src/product/price/PriceTypeDefinition.php index 1c2a2770..30b4dba4 100644 --- a/src/product/price/PriceTypeDefinition.php +++ b/src/product/price/PriceTypeDefinition.php @@ -4,9 +4,8 @@ namespace hiqdev\php\billing\product\price; use hiqdev\php\billing\product\AggregateInterface; -use hiqdev\php\billing\product\behavior\BehaviorCollectionInterface; -use hiqdev\php\billing\product\behavior\BehaviorInterface; use hiqdev\php\billing\product\behavior\HasBehaviorsInterface; +use hiqdev\php\billing\product\behavior\PriceTypeBehaviourRegistry; use hiqdev\php\billing\product\Exception\AggregateNotDefinedException; use hiqdev\php\billing\product\behavior\BehaviorPriceTypeDefinitionCollection; use hiqdev\php\billing\product\invoice\RepresentationCollection; @@ -22,6 +21,7 @@ use hiqdev\php\billing\product\TariffTypeDefinitionInterface; use hiqdev\php\billing\product\trait\HasLock; use hiqdev\php\billing\type\TypeInterface; +use function class_exists; /** * @template TParentCollection @@ -46,16 +46,13 @@ class PriceTypeDefinition implements PriceTypeDefinitionInterface */ private RepresentationCollection $representationCollection; - /** - * @var BehaviorPriceTypeDefinitionCollection - */ - private BehaviorPriceTypeDefinitionCollection $behaviorCollection; - private ?AggregateInterface $aggregate = null; /** @psalm-var TParentCollection */ private readonly PriceTypeDefinitionCollectionInterface $parent; + private readonly PriceTypeBehaviourRegistry $behaviorRegistry; + /** * @param TParentCollection $parent */ @@ -66,7 +63,7 @@ public function __construct( ) { $this->parent = $parent; $this->representationCollection = new RepresentationCollection($this); - $this->behaviorCollection = new BehaviorPriceTypeDefinitionCollection($this, $tariffType); + $this->behaviorRegistry = new PriceTypeBehaviourRegistry($this, $tariffType); $this->init(); } @@ -107,7 +104,7 @@ public function quantityFormatter(string $formatterClass, $fractionUnit = null): { $this->ensureNotLocked(); - if (!\class_exists($formatterClass)) { + if (!class_exists($formatterClass)) { throw new InvalidQuantityFormatterException("Formatter class $formatterClass does not exist"); } @@ -181,29 +178,17 @@ public function withBehaviors() { $this->ensureNotLocked(); - return $this->behaviorCollection; + return $this->behaviorRegistry->withBehaviors(); } public function hasBehavior(string $behaviorClassName): bool { - foreach ($this->behaviorCollection as $behavior) { - if ($behavior instanceof $behaviorClassName) { - return true; - } - } - - return false; + return $this->behaviorRegistry->hasBehavior($behaviorClassName); } - public function findBehaviorByClass(string $class): ?BehaviorInterface + public function findBehaviorByClass(string $class) { - foreach ($this->behaviorCollection as $behavior) { - if ($behavior instanceof $class) { - return $behavior; - } - } - - return null; + return $this->behaviorRegistry->findBehaviorByClass($class); } /** @@ -242,7 +227,7 @@ public function getQuantityFormatterDefinition(): ?QuantityFormatterDefinition protected function afterLock(): void { $this->representationCollection->lock(); - $this->behaviorCollection->lock(); + $this->behaviorRegistry->lock(); } public function getTariffTypeDefinition(): TariffTypeDefinitionInterface diff --git a/tests/unit/product/behavior/TariffTypeBehaviorRegistryTest.php b/tests/unit/product/behavior/TariffTypeBehaviorRegistryTest.php index b5c11406..f861388c 100644 --- a/tests/unit/product/behavior/TariffTypeBehaviorRegistryTest.php +++ b/tests/unit/product/behavior/TariffTypeBehaviorRegistryTest.php @@ -21,7 +21,7 @@ protected function setUp(): void public function testWithBehaviorsReturnsBehaviorCollection(): void { - $this->assertInstanceOf(BehaviorTariffTypeCollection::class, $this->manager->getBehaviors()); + $this->assertInstanceOf(BehaviorTariffTypeCollection::class, $this->manager->withBehaviors()); } public function testHasBehaviorReturnsFalseWhenBehaviorNotPresent(): void @@ -32,7 +32,7 @@ public function testHasBehaviorReturnsFalseWhenBehaviorNotPresent(): void public function testHasBehaviorReturnsTrueWhenBehaviorPresent(): void { $behavior = $this->createMock(TestBehavior::class); - $behaviorCollection = $this->manager->getBehaviors(); + $behaviorCollection = $this->manager->withBehaviors(); $behaviorCollection->attach($behavior); $this->assertTrue($this->manager->hasBehavior(TestBehavior::class)); From ca6bc903c760b2c19b46000cdeaee0f847924733 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Sun, 10 Aug 2025 14:34:14 +0300 Subject: [PATCH 02/11] HP-2496: fixing Psalm --- src/product/behavior/BehaviorRegistry.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/product/behavior/BehaviorRegistry.php b/src/product/behavior/BehaviorRegistry.php index 2364209c..6cc39c23 100644 --- a/src/product/behavior/BehaviorRegistry.php +++ b/src/product/behavior/BehaviorRegistry.php @@ -6,8 +6,15 @@ use hiqdev\php\billing\product\trait\HasLockInterface; +/** + * @template TParentCollection + * @implements HasBehaviorsInterface + */ abstract class BehaviorRegistry implements HasLockInterface, HasBehaviorsInterface { + /** + * @return BehaviorCollectionInterface + */ abstract protected function getBehaviorCollection(): BehaviorCollectionInterface; public function hasBehavior(string $behaviorClassName): bool @@ -23,7 +30,7 @@ public function hasBehavior(string $behaviorClassName): bool public function findBehaviorByClass(string $class) { - foreach ($this->withBehaviors() as $behavior) { + foreach ($this->getBehaviorCollection() as $behavior) { if ($behavior instanceof $class) { return $behavior; } From 2f7d6054a7690d4b9973891fc0a03cbbf495d467 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Sun, 10 Aug 2025 14:36:21 +0300 Subject: [PATCH 03/11] HP-2496: fixing Psalm --- src/product/behavior/BehaviorRegistry.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/product/behavior/BehaviorRegistry.php b/src/product/behavior/BehaviorRegistry.php index 6cc39c23..67439261 100644 --- a/src/product/behavior/BehaviorRegistry.php +++ b/src/product/behavior/BehaviorRegistry.php @@ -4,10 +4,12 @@ namespace hiqdev\php\billing\product\behavior; +use hiqdev\php\billing\product\price\PriceTypeDefinitionInterface; +use hiqdev\php\billing\product\TariffTypeDefinitionInterface; use hiqdev\php\billing\product\trait\HasLockInterface; /** - * @template TParentCollection + * @template TParentCollection of PriceTypeDefinitionInterface|TariffTypeDefinitionInterface * @implements HasBehaviorsInterface */ abstract class BehaviorRegistry implements HasLockInterface, HasBehaviorsInterface From f253628d5a5ff663b7abbe2d7ab85d9a739398a7 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Sun, 10 Aug 2025 14:38:34 +0300 Subject: [PATCH 04/11] HP-2496: fixing Psalm --- src/product/behavior/PriceTypeBehaviourRegistry.php | 1 + src/product/behavior/TariffTypeBehaviorRegistry.php | 1 + 2 files changed, 2 insertions(+) diff --git a/src/product/behavior/PriceTypeBehaviourRegistry.php b/src/product/behavior/PriceTypeBehaviourRegistry.php index dc9eb9c5..99e89893 100644 --- a/src/product/behavior/PriceTypeBehaviourRegistry.php +++ b/src/product/behavior/PriceTypeBehaviourRegistry.php @@ -9,6 +9,7 @@ /** * @template T as PriceTypeDefinitionInterface + * @extends BehaviorRegistry */ final class PriceTypeBehaviourRegistry extends BehaviorRegistry { diff --git a/src/product/behavior/TariffTypeBehaviorRegistry.php b/src/product/behavior/TariffTypeBehaviorRegistry.php index 1644bb16..75824476 100644 --- a/src/product/behavior/TariffTypeBehaviorRegistry.php +++ b/src/product/behavior/TariffTypeBehaviorRegistry.php @@ -25,6 +25,7 @@ * - To improve maintainability and testability of tariff behavior handling. * * @template-covariant T of TariffTypeDefinitionInterface + * @extends BehaviorRegistry */ final class TariffTypeBehaviorRegistry extends BehaviorRegistry { From 8064c4a38ecf4f61642a4ee91b1463a2747a8f0b Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Sun, 10 Aug 2025 18:13:42 +0300 Subject: [PATCH 05/11] HP-2496: tiny --- ...eBehaviourRegistry.php => PriceTypeBehaviorRegistry.php} | 2 +- src/product/price/PriceTypeDefinition.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) rename src/product/behavior/{PriceTypeBehaviourRegistry.php => PriceTypeBehaviorRegistry.php} (94%) diff --git a/src/product/behavior/PriceTypeBehaviourRegistry.php b/src/product/behavior/PriceTypeBehaviorRegistry.php similarity index 94% rename from src/product/behavior/PriceTypeBehaviourRegistry.php rename to src/product/behavior/PriceTypeBehaviorRegistry.php index 99e89893..65a7dc6e 100644 --- a/src/product/behavior/PriceTypeBehaviourRegistry.php +++ b/src/product/behavior/PriceTypeBehaviorRegistry.php @@ -11,7 +11,7 @@ * @template T as PriceTypeDefinitionInterface * @extends BehaviorRegistry */ -final class PriceTypeBehaviourRegistry extends BehaviorRegistry +final class PriceTypeBehaviorRegistry extends BehaviorRegistry { /** * @var BehaviorPriceTypeDefinitionCollection diff --git a/src/product/price/PriceTypeDefinition.php b/src/product/price/PriceTypeDefinition.php index 30b4dba4..1e3b4aa4 100644 --- a/src/product/price/PriceTypeDefinition.php +++ b/src/product/price/PriceTypeDefinition.php @@ -5,7 +5,7 @@ use hiqdev\php\billing\product\AggregateInterface; use hiqdev\php\billing\product\behavior\HasBehaviorsInterface; -use hiqdev\php\billing\product\behavior\PriceTypeBehaviourRegistry; +use hiqdev\php\billing\product\behavior\PriceTypeBehaviorRegistry; use hiqdev\php\billing\product\Exception\AggregateNotDefinedException; use hiqdev\php\billing\product\behavior\BehaviorPriceTypeDefinitionCollection; use hiqdev\php\billing\product\invoice\RepresentationCollection; @@ -51,7 +51,7 @@ class PriceTypeDefinition implements PriceTypeDefinitionInterface /** @psalm-var TParentCollection */ private readonly PriceTypeDefinitionCollectionInterface $parent; - private readonly PriceTypeBehaviourRegistry $behaviorRegistry; + private readonly PriceTypeBehaviorRegistry $behaviorRegistry; /** * @param TParentCollection $parent @@ -63,7 +63,7 @@ public function __construct( ) { $this->parent = $parent; $this->representationCollection = new RepresentationCollection($this); - $this->behaviorRegistry = new PriceTypeBehaviourRegistry($this, $tariffType); + $this->behaviorRegistry = new PriceTypeBehaviorRegistry($this, $tariffType); $this->init(); } From 1a99cc47b463b9ae228d2e09a92229e522953e7f Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Sun, 10 Aug 2025 18:21:50 +0300 Subject: [PATCH 06/11] HP-2496: tiny --- src/product/behavior/HasBehaviorsInterface.php | 5 +++++ src/product/behavior/PriceTypeBehaviorRegistry.php | 8 ++++---- src/product/behavior/TariffTypeBehaviorRegistry.php | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/product/behavior/HasBehaviorsInterface.php b/src/product/behavior/HasBehaviorsInterface.php index 007ca68c..204cf893 100644 --- a/src/product/behavior/HasBehaviorsInterface.php +++ b/src/product/behavior/HasBehaviorsInterface.php @@ -18,5 +18,10 @@ public function withBehaviors(); public function hasBehavior(string $behaviorClassName): bool; + /** + * @template TBehavior of object + * @param class-string $class + * @return TBehavior|null + */ public function findBehaviorByClass(string $class); } diff --git a/src/product/behavior/PriceTypeBehaviorRegistry.php b/src/product/behavior/PriceTypeBehaviorRegistry.php index 65a7dc6e..35100747 100644 --- a/src/product/behavior/PriceTypeBehaviorRegistry.php +++ b/src/product/behavior/PriceTypeBehaviorRegistry.php @@ -9,7 +9,7 @@ /** * @template T as PriceTypeDefinitionInterface - * @extends BehaviorRegistry + * @extends BehaviorRegistry */ final class PriceTypeBehaviorRegistry extends BehaviorRegistry { @@ -19,11 +19,11 @@ final class PriceTypeBehaviorRegistry extends BehaviorRegistry private BehaviorPriceTypeDefinitionCollection $behaviorCollection; /** - * @psalm-param T $tariffTypeDefinition + * @psalm-param T $priceTypeDefinition */ - public function __construct(PriceTypeDefinitionInterface $tariffTypeDefinition, TariffTypeInterface $tariffType) + public function __construct(PriceTypeDefinitionInterface $priceTypeDefinition, TariffTypeInterface $tariffType) { - $this->behaviorCollection = new BehaviorPriceTypeDefinitionCollection($tariffTypeDefinition, $tariffType); + $this->behaviorCollection = new BehaviorPriceTypeDefinitionCollection($priceTypeDefinition, $tariffType); } /** diff --git a/src/product/behavior/TariffTypeBehaviorRegistry.php b/src/product/behavior/TariffTypeBehaviorRegistry.php index 75824476..73fd21d1 100644 --- a/src/product/behavior/TariffTypeBehaviorRegistry.php +++ b/src/product/behavior/TariffTypeBehaviorRegistry.php @@ -25,7 +25,7 @@ * - To improve maintainability and testability of tariff behavior handling. * * @template-covariant T of TariffTypeDefinitionInterface - * @extends BehaviorRegistry + * @extends BehaviorRegistry */ final class TariffTypeBehaviorRegistry extends BehaviorRegistry { From 5b5cf268865712178d36637f79eb62445f255278 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Sun, 10 Aug 2025 20:23:34 +0300 Subject: [PATCH 07/11] HP-2496: tiny --- src/product/behavior/BehaviorRegistry.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/product/behavior/BehaviorRegistry.php b/src/product/behavior/BehaviorRegistry.php index 67439261..82a339d5 100644 --- a/src/product/behavior/BehaviorRegistry.php +++ b/src/product/behavior/BehaviorRegistry.php @@ -9,7 +9,7 @@ use hiqdev\php\billing\product\trait\HasLockInterface; /** - * @template TParentCollection of PriceTypeDefinitionInterface|TariffTypeDefinitionInterface + * @template-covariant TParentCollection of PriceTypeDefinitionInterface|TariffTypeDefinitionInterface * @implements HasBehaviorsInterface */ abstract class BehaviorRegistry implements HasLockInterface, HasBehaviorsInterface From da60a936348c49ed615420f059a910d618101dad Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Sun, 10 Aug 2025 20:28:57 +0300 Subject: [PATCH 08/11] HP-2496: fixing psalm --- src/product/behavior/PriceTypeBehaviorRegistry.php | 3 +-- src/product/behavior/TariffTypeBehaviorRegistry.php | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/product/behavior/PriceTypeBehaviorRegistry.php b/src/product/behavior/PriceTypeBehaviorRegistry.php index 35100747..a49387fd 100644 --- a/src/product/behavior/PriceTypeBehaviorRegistry.php +++ b/src/product/behavior/PriceTypeBehaviorRegistry.php @@ -8,8 +8,7 @@ use hiqdev\php\billing\product\price\PriceTypeDefinitionInterface; /** - * @template T as PriceTypeDefinitionInterface - * @extends BehaviorRegistry + * @extends BehaviorRegistry */ final class PriceTypeBehaviorRegistry extends BehaviorRegistry { diff --git a/src/product/behavior/TariffTypeBehaviorRegistry.php b/src/product/behavior/TariffTypeBehaviorRegistry.php index 73fd21d1..ec7d7ef3 100644 --- a/src/product/behavior/TariffTypeBehaviorRegistry.php +++ b/src/product/behavior/TariffTypeBehaviorRegistry.php @@ -24,8 +24,7 @@ * - To separate concerns by handling behavior-related logic in a dedicated class. * - To improve maintainability and testability of tariff behavior handling. * - * @template-covariant T of TariffTypeDefinitionInterface - * @extends BehaviorRegistry + * @extends BehaviorRegistry */ final class TariffTypeBehaviorRegistry extends BehaviorRegistry { From e6fe816a0c8b58900543d367ba330e663f5cba46 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Sun, 10 Aug 2025 20:31:05 +0300 Subject: [PATCH 09/11] HP-2496: fixing psalm --- src/product/behavior/PriceTypeBehaviorRegistry.php | 6 +++--- src/product/behavior/TariffTypeBehaviorRegistry.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/product/behavior/PriceTypeBehaviorRegistry.php b/src/product/behavior/PriceTypeBehaviorRegistry.php index a49387fd..6c4faa1a 100644 --- a/src/product/behavior/PriceTypeBehaviorRegistry.php +++ b/src/product/behavior/PriceTypeBehaviorRegistry.php @@ -13,12 +13,12 @@ final class PriceTypeBehaviorRegistry extends BehaviorRegistry { /** - * @var BehaviorPriceTypeDefinitionCollection + * @var BehaviorPriceTypeDefinitionCollection */ private BehaviorPriceTypeDefinitionCollection $behaviorCollection; /** - * @psalm-param T $priceTypeDefinition + * @psalm-param PriceTypeDefinitionInterface $priceTypeDefinition */ public function __construct(PriceTypeDefinitionInterface $priceTypeDefinition, TariffTypeInterface $tariffType) { @@ -26,7 +26,7 @@ public function __construct(PriceTypeDefinitionInterface $priceTypeDefinition, T } /** - * @return BehaviorPriceTypeDefinitionCollection + * @return BehaviorPriceTypeDefinitionCollection */ public function withBehaviors(): BehaviorPriceTypeDefinitionCollection { diff --git a/src/product/behavior/TariffTypeBehaviorRegistry.php b/src/product/behavior/TariffTypeBehaviorRegistry.php index ec7d7ef3..121d248d 100644 --- a/src/product/behavior/TariffTypeBehaviorRegistry.php +++ b/src/product/behavior/TariffTypeBehaviorRegistry.php @@ -29,12 +29,12 @@ final class TariffTypeBehaviorRegistry extends BehaviorRegistry { /** - * @var BehaviorTariffTypeCollection + * @var BehaviorTariffTypeCollection */ private BehaviorTariffTypeCollection $behaviorCollection; /** - * @psalm-param T $tariffTypeDefinition + * @psalm-param TariffTypeDefinitionInterface $tariffTypeDefinition */ public function __construct(TariffTypeDefinitionInterface $tariffTypeDefinition, TariffTypeInterface $tariffType) { @@ -42,7 +42,7 @@ public function __construct(TariffTypeDefinitionInterface $tariffTypeDefinition, } /** - * @return BehaviorTariffTypeCollection + * @return BehaviorTariffTypeCollection */ public function withBehaviors(): BehaviorTariffTypeCollection { From c4cb9dff2d6223105db91df1ae67f0794d27ce46 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Mon, 11 Aug 2025 04:11:33 +0300 Subject: [PATCH 10/11] HP-2496: fixing psalm --- src/product/behavior/BehaviorRegistry.php | 17 +++-------------- .../behavior/PriceTypeBehaviorRegistry.php | 8 ++++---- .../behavior/TariffTypeBehaviorRegistry.php | 8 ++++---- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/src/product/behavior/BehaviorRegistry.php b/src/product/behavior/BehaviorRegistry.php index 82a339d5..5fa0f360 100644 --- a/src/product/behavior/BehaviorRegistry.php +++ b/src/product/behavior/BehaviorRegistry.php @@ -4,24 +4,13 @@ namespace hiqdev\php\billing\product\behavior; -use hiqdev\php\billing\product\price\PriceTypeDefinitionInterface; -use hiqdev\php\billing\product\TariffTypeDefinitionInterface; use hiqdev\php\billing\product\trait\HasLockInterface; -/** - * @template-covariant TParentCollection of PriceTypeDefinitionInterface|TariffTypeDefinitionInterface - * @implements HasBehaviorsInterface - */ abstract class BehaviorRegistry implements HasLockInterface, HasBehaviorsInterface { - /** - * @return BehaviorCollectionInterface - */ - abstract protected function getBehaviorCollection(): BehaviorCollectionInterface; - public function hasBehavior(string $behaviorClassName): bool { - foreach ($this->getBehaviorCollection() as $behavior) { + foreach ($this->withBehaviors() as $behavior) { if ($behavior instanceof $behaviorClassName) { return true; } @@ -32,7 +21,7 @@ public function hasBehavior(string $behaviorClassName): bool public function findBehaviorByClass(string $class) { - foreach ($this->getBehaviorCollection() as $behavior) { + foreach ($this->withBehaviors() as $behavior) { if ($behavior instanceof $class) { return $behavior; } @@ -43,6 +32,6 @@ public function findBehaviorByClass(string $class) public function lock(): void { - $this->getBehaviorCollection()->lock(); + $this->withBehaviors()->lock(); } } diff --git a/src/product/behavior/PriceTypeBehaviorRegistry.php b/src/product/behavior/PriceTypeBehaviorRegistry.php index 6c4faa1a..cc09de2b 100644 --- a/src/product/behavior/PriceTypeBehaviorRegistry.php +++ b/src/product/behavior/PriceTypeBehaviorRegistry.php @@ -8,17 +8,17 @@ use hiqdev\php\billing\product\price\PriceTypeDefinitionInterface; /** - * @extends BehaviorRegistry + * @template-covariant T of PriceTypeDefinitionInterface */ final class PriceTypeBehaviorRegistry extends BehaviorRegistry { /** - * @var BehaviorPriceTypeDefinitionCollection + * @var BehaviorPriceTypeDefinitionCollection */ private BehaviorPriceTypeDefinitionCollection $behaviorCollection; /** - * @psalm-param PriceTypeDefinitionInterface $priceTypeDefinition + * @psalm-param T $priceTypeDefinition */ public function __construct(PriceTypeDefinitionInterface $priceTypeDefinition, TariffTypeInterface $tariffType) { @@ -26,7 +26,7 @@ public function __construct(PriceTypeDefinitionInterface $priceTypeDefinition, T } /** - * @return BehaviorPriceTypeDefinitionCollection + * @return BehaviorPriceTypeDefinitionCollection */ public function withBehaviors(): BehaviorPriceTypeDefinitionCollection { diff --git a/src/product/behavior/TariffTypeBehaviorRegistry.php b/src/product/behavior/TariffTypeBehaviorRegistry.php index 121d248d..1644bb16 100644 --- a/src/product/behavior/TariffTypeBehaviorRegistry.php +++ b/src/product/behavior/TariffTypeBehaviorRegistry.php @@ -24,17 +24,17 @@ * - To separate concerns by handling behavior-related logic in a dedicated class. * - To improve maintainability and testability of tariff behavior handling. * - * @extends BehaviorRegistry + * @template-covariant T of TariffTypeDefinitionInterface */ final class TariffTypeBehaviorRegistry extends BehaviorRegistry { /** - * @var BehaviorTariffTypeCollection + * @var BehaviorTariffTypeCollection */ private BehaviorTariffTypeCollection $behaviorCollection; /** - * @psalm-param TariffTypeDefinitionInterface $tariffTypeDefinition + * @psalm-param T $tariffTypeDefinition */ public function __construct(TariffTypeDefinitionInterface $tariffTypeDefinition, TariffTypeInterface $tariffType) { @@ -42,7 +42,7 @@ public function __construct(TariffTypeDefinitionInterface $tariffTypeDefinition, } /** - * @return BehaviorTariffTypeCollection + * @return BehaviorTariffTypeCollection */ public function withBehaviors(): BehaviorTariffTypeCollection { From 9f10707409b69b5e5841867b0e6cf2b37009ab42 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Mon, 11 Aug 2025 04:18:57 +0300 Subject: [PATCH 11/11] HP-2496: fixing psalm --- src/product/behavior/BehaviorRegistry.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/product/behavior/BehaviorRegistry.php b/src/product/behavior/BehaviorRegistry.php index 5fa0f360..dfd73b1a 100644 --- a/src/product/behavior/BehaviorRegistry.php +++ b/src/product/behavior/BehaviorRegistry.php @@ -6,6 +6,10 @@ use hiqdev\php\billing\product\trait\HasLockInterface; +/** + * @psalm-suppress MissingTemplateParam + * @psalm-suppress InvalidTemplateParam + */ abstract class BehaviorRegistry implements HasLockInterface, HasBehaviorsInterface { public function hasBehavior(string $behaviorClassName): bool