Skip to content

Commit 0e2bcb0

Browse files
HP-1751 lock BehaviorCollections after call end() method
1 parent a7f2110 commit 0e2bcb0

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

src/product/behavior/BehaviorCollection.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
namespace hiqdev\php\billing\product\behavior;
44

55
use hiqdev\php\billing\product\Domain\Model\TariffTypeInterface;
6+
use hiqdev\php\billing\product\trait\HasLock;
67

78
abstract class BehaviorCollection implements BehaviorCollectionInterface
89
{
10+
use HasLock;
11+
912
/** @var BehaviorInterface[] */
1013
private array $behaviors = [];
1114

@@ -20,6 +23,8 @@ public function getIterator(): \Traversable
2023

2124
public function attach(BehaviorInterface $behavior): self
2225
{
26+
$this->ensureNotLocked();
27+
2328
$behavior->setTariffType($this->tariffType);
2429

2530
$this->behaviors[] = $behavior;

src/product/behavior/BehaviorPriceTypeDefinitionCollection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public function __construct(private readonly PriceTypeDefinitionInterface $paren
1414

1515
public function end(): PriceTypeDefinitionInterface
1616
{
17+
$this->lock();
18+
1719
return $this->parent;
1820
}
1921
}

src/product/behavior/BehaviorTariffTypeCollection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public function __construct(private readonly TariffTypeDefinitionInterface $pare
1414

1515
public function end(): TariffTypeDefinitionInterface
1616
{
17+
$this->lock();
18+
1719
return $this->parent;
1820
}
1921
}

0 commit comments

Comments
 (0)