Skip to content

Commit c4cb9df

Browse files
HP-2496: fixing psalm
1 parent e6fe816 commit c4cb9df

File tree

3 files changed

+11
-22
lines changed

3 files changed

+11
-22
lines changed

src/product/behavior/BehaviorRegistry.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,13 @@
44

55
namespace hiqdev\php\billing\product\behavior;
66

7-
use hiqdev\php\billing\product\price\PriceTypeDefinitionInterface;
8-
use hiqdev\php\billing\product\TariffTypeDefinitionInterface;
97
use hiqdev\php\billing\product\trait\HasLockInterface;
108

11-
/**
12-
* @template-covariant TParentCollection of PriceTypeDefinitionInterface|TariffTypeDefinitionInterface
13-
* @implements HasBehaviorsInterface<TParentCollection>
14-
*/
159
abstract class BehaviorRegistry implements HasLockInterface, HasBehaviorsInterface
1610
{
17-
/**
18-
* @return BehaviorCollectionInterface<TParentCollection>
19-
*/
20-
abstract protected function getBehaviorCollection(): BehaviorCollectionInterface;
21-
2211
public function hasBehavior(string $behaviorClassName): bool
2312
{
24-
foreach ($this->getBehaviorCollection() as $behavior) {
13+
foreach ($this->withBehaviors() as $behavior) {
2514
if ($behavior instanceof $behaviorClassName) {
2615
return true;
2716
}
@@ -32,7 +21,7 @@ public function hasBehavior(string $behaviorClassName): bool
3221

3322
public function findBehaviorByClass(string $class)
3423
{
35-
foreach ($this->getBehaviorCollection() as $behavior) {
24+
foreach ($this->withBehaviors() as $behavior) {
3625
if ($behavior instanceof $class) {
3726
return $behavior;
3827
}
@@ -43,6 +32,6 @@ public function findBehaviorByClass(string $class)
4332

4433
public function lock(): void
4534
{
46-
$this->getBehaviorCollection()->lock();
35+
$this->withBehaviors()->lock();
4736
}
4837
}

src/product/behavior/PriceTypeBehaviorRegistry.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@
88
use hiqdev\php\billing\product\price\PriceTypeDefinitionInterface;
99

1010
/**
11-
* @extends BehaviorRegistry<PriceTypeDefinitionInterface>
11+
* @template-covariant T of PriceTypeDefinitionInterface
1212
*/
1313
final class PriceTypeBehaviorRegistry extends BehaviorRegistry
1414
{
1515
/**
16-
* @var BehaviorPriceTypeDefinitionCollection<PriceTypeDefinitionInterface>
16+
* @var BehaviorPriceTypeDefinitionCollection<T>
1717
*/
1818
private BehaviorPriceTypeDefinitionCollection $behaviorCollection;
1919

2020
/**
21-
* @psalm-param PriceTypeDefinitionInterface $priceTypeDefinition
21+
* @psalm-param T $priceTypeDefinition
2222
*/
2323
public function __construct(PriceTypeDefinitionInterface $priceTypeDefinition, TariffTypeInterface $tariffType)
2424
{
2525
$this->behaviorCollection = new BehaviorPriceTypeDefinitionCollection($priceTypeDefinition, $tariffType);
2626
}
2727

2828
/**
29-
* @return BehaviorPriceTypeDefinitionCollection<PriceTypeDefinitionInterface>
29+
* @return BehaviorPriceTypeDefinitionCollection<T>
3030
*/
3131
public function withBehaviors(): BehaviorPriceTypeDefinitionCollection
3232
{

src/product/behavior/TariffTypeBehaviorRegistry.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,25 @@
2424
* - To separate concerns by handling behavior-related logic in a dedicated class.
2525
* - To improve maintainability and testability of tariff behavior handling.
2626
*
27-
* @extends BehaviorRegistry<TariffTypeDefinitionInterface>
27+
* @template-covariant T of TariffTypeDefinitionInterface
2828
*/
2929
final class TariffTypeBehaviorRegistry extends BehaviorRegistry
3030
{
3131
/**
32-
* @var BehaviorTariffTypeCollection<TariffTypeDefinitionInterface>
32+
* @var BehaviorTariffTypeCollection<T>
3333
*/
3434
private BehaviorTariffTypeCollection $behaviorCollection;
3535

3636
/**
37-
* @psalm-param TariffTypeDefinitionInterface $tariffTypeDefinition
37+
* @psalm-param T $tariffTypeDefinition
3838
*/
3939
public function __construct(TariffTypeDefinitionInterface $tariffTypeDefinition, TariffTypeInterface $tariffType)
4040
{
4141
$this->behaviorCollection = new BehaviorTariffTypeCollection($tariffTypeDefinition, $tariffType);
4242
}
4343

4444
/**
45-
* @return BehaviorTariffTypeCollection<TariffTypeDefinitionInterface>
45+
* @return BehaviorTariffTypeCollection<T>
4646
*/
4747
public function withBehaviors(): BehaviorTariffTypeCollection
4848
{

0 commit comments

Comments
 (0)