Passed
Pull Request — master (#99)
by
unknown
02:46
created

BehaviorCollection   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 25
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A attach() 0 9 1
A __construct() 0 2 1
A getIterator() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace hiqdev\php\billing\product\behavior;
4
5
use hiqdev\php\billing\product\Domain\Model\TariffTypeInterface;
6
use hiqdev\php\billing\product\trait\HasLock;
7
8
abstract class BehaviorCollection implements BehaviorCollectionInterface
9
{
10
    use HasLock;
11
12
    /** @var BehaviorInterface[] */
13
    private array $behaviors = [];
14
15
    public function __construct(private readonly TariffTypeInterface $tariffType)
16
    {
17
    }
18
19
    public function getIterator(): \Traversable
20
    {
21
        return new \ArrayIterator($this->behaviors);
22
    }
23
24
    public function attach(BehaviorInterface $behavior): self
25
    {
26
        $this->ensureNotLocked();
27
28
        $behavior->setTariffType($this->tariffType);
29
30
        $this->behaviors[] = $behavior;
31
32
        return $this;
33
    }
34
}
35