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

BehaviorCollection::getIterator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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