Passed
Pull Request — master (#104)
by
unknown
02:45 queued 23s
created

BehaviorRegistry::lock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace hiqdev\php\billing\product\behavior;
6
7
use hiqdev\php\billing\product\price\PriceTypeDefinitionInterface;
8
use hiqdev\php\billing\product\TariffTypeDefinitionInterface;
9
use hiqdev\php\billing\product\trait\HasLockInterface;
10
11
/**
12
 * @template-covariant TParentCollection of PriceTypeDefinitionInterface|TariffTypeDefinitionInterface
13
 * @implements HasBehaviorsInterface<TParentCollection>
14
 */
15
abstract class BehaviorRegistry implements HasLockInterface, HasBehaviorsInterface
16
{
17
    /**
18
     * @return BehaviorCollectionInterface<TParentCollection>
19
     */
20
    abstract protected function getBehaviorCollection(): BehaviorCollectionInterface;
21
22
    public function hasBehavior(string $behaviorClassName): bool
23
    {
24
        foreach ($this->getBehaviorCollection() as $behavior) {
25
            if ($behavior instanceof $behaviorClassName) {
26
                return true;
27
            }
28
        }
29
30
        return false;
31
    }
32
33
    public function findBehaviorByClass(string $class)
34
    {
35
        foreach ($this->getBehaviorCollection() as $behavior) {
36
            if ($behavior instanceof $class) {
37
                return $behavior;
38
            }
39
        }
40
41
        return null;
42
    }
43
44
    public function lock(): void
45
    {
46
        $this->getBehaviorCollection()->lock();
47
    }
48
}
49