|
5 | 5 | use hiqdev\php\billing\product\Domain\Model\TariffTypeInterface; |
6 | 6 | use hiqdev\php\billing\product\TariffTypeDefinitionInterface; |
7 | 7 |
|
| 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 | + */ |
8 | 25 | final class TariffTypeBehaviorRegistry |
9 | 26 | { |
10 | | - private BehaviorTariffTypeCollection $behaviorCollection; |
| 27 | + private BehaviorTariffTypeCollection $behaviors; |
11 | 28 |
|
12 | 29 | public function __construct(TariffTypeDefinitionInterface $tariffTypeDefinition, TariffTypeInterface $tariffType) |
13 | 30 | { |
14 | | - $this->behaviorCollection = new BehaviorTariffTypeCollection($tariffTypeDefinition, $tariffType); |
| 31 | + $this->behaviors = new BehaviorTariffTypeCollection($tariffTypeDefinition, $tariffType); |
15 | 32 | } |
16 | 33 |
|
17 | | - public function withBehaviors(): BehaviorTariffTypeCollection |
| 34 | + public function getBehaviors(): BehaviorTariffTypeCollection |
18 | 35 | { |
19 | | - return $this->behaviorCollection; |
| 36 | + return $this->behaviors; |
20 | 37 | } |
21 | 38 |
|
22 | 39 | public function hasBehavior(string $behaviorClassName): bool |
23 | 40 | { |
24 | | - foreach ($this->behaviorCollection as $behavior) { |
| 41 | + foreach ($this->behaviors as $behavior) { |
25 | 42 | if ($behavior instanceof $behaviorClassName) { |
26 | 43 | return true; |
27 | 44 | } |
|
0 commit comments