Skip to content

Commit 8da4e9a

Browse files
HP-1751 added description to TariffTypeBehaviorRegistry class
1 parent b6aada3 commit 8da4e9a

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

src/product/TariffTypeDefinition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function withBehaviors(): BehaviorTariffTypeCollection
7979
{
8080
$this->ensureNotLocked();
8181

82-
return $this->tariffTypeBehaviorRegistry->withBehaviors();
82+
return $this->tariffTypeBehaviorRegistry->getBehaviors();
8383
}
8484

8585
public function hasBehavior(string $behaviorClassName): bool

src/product/behavior/TariffTypeBehaviorRegistry.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,40 @@
55
use hiqdev\php\billing\product\Domain\Model\TariffTypeInterface;
66
use hiqdev\php\billing\product\TariffTypeDefinitionInterface;
77

8+
/**
9+
* class TariffTypeBehaviorRegistry
10+
*
11+
* This class acts as a registry for tariff behaviors, encapsulating
12+
* the BehaviorTariffTypeCollection to provide structured access
13+
* and behavior lookup functionalities.
14+
*
15+
* Purpose:
16+
* - Stores a collection of behaviors associated with a TariffType.
17+
* - Provides access to the behavior collection via getBehaviors().
18+
* - Allows checking for the existence of a specific behavior using hasBehavior().
19+
*
20+
* Why this class was created:
21+
* - To avoid code duplication of behavior-related methods in multiple classes.
22+
* - To separate concerns by handling behavior-related logic in a dedicated class.
23+
* - To improve maintainability and testability of tariff behavior handling.
24+
*/
825
final class TariffTypeBehaviorRegistry
926
{
10-
private BehaviorTariffTypeCollection $behaviorCollection;
27+
private BehaviorTariffTypeCollection $behaviors;
1128

1229
public function __construct(TariffTypeDefinitionInterface $tariffTypeDefinition, TariffTypeInterface $tariffType)
1330
{
14-
$this->behaviorCollection = new BehaviorTariffTypeCollection($tariffTypeDefinition, $tariffType);
31+
$this->behaviors = new BehaviorTariffTypeCollection($tariffTypeDefinition, $tariffType);
1532
}
1633

17-
public function withBehaviors(): BehaviorTariffTypeCollection
34+
public function getBehaviors(): BehaviorTariffTypeCollection
1835
{
19-
return $this->behaviorCollection;
36+
return $this->behaviors;
2037
}
2138

2239
public function hasBehavior(string $behaviorClassName): bool
2340
{
24-
foreach ($this->behaviorCollection as $behavior) {
41+
foreach ($this->behaviors as $behavior) {
2542
if ($behavior instanceof $behaviorClassName) {
2643
return true;
2744
}

tests/unit/product/behavior/TariffTypeBehaviorRegistryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ protected function setUp(): void
2121

2222
public function testWithBehaviorsReturnsBehaviorCollection(): void
2323
{
24-
$this->assertInstanceOf(BehaviorTariffTypeCollection::class, $this->manager->withBehaviors());
24+
$this->assertInstanceOf(BehaviorTariffTypeCollection::class, $this->manager->getBehaviors());
2525
}
2626

2727
public function testHasBehaviorReturnsFalseWhenBehaviorNotPresent(): void
@@ -32,7 +32,7 @@ public function testHasBehaviorReturnsFalseWhenBehaviorNotPresent(): void
3232
public function testHasBehaviorReturnsTrueWhenBehaviorPresent(): void
3333
{
3434
$behavior = $this->createMock(TestBehavior::class);
35-
$behaviorCollection = $this->manager->withBehaviors();
35+
$behaviorCollection = $this->manager->getBehaviors();
3636
$behaviorCollection->attach($behavior);
3737

3838
$this->assertTrue($this->manager->hasBehavior(TestBehavior::class));

0 commit comments

Comments
 (0)