Behaviours::remove()   A
last analyzed

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
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Sirius\Orm\Entity;
5
6
use Sirius\Orm\Behaviour\BehaviourInterface;
7
use Sirius\Orm\Helpers\Str;
8
9
class Behaviours
10
{
11
12
    protected $list = [];
13
14
    public function add(BehaviourInterface $behaviour)
15
    {
16
        $this->list[$behaviour->getName()] = $behaviour;
17
    }
18
19
    public function remove($name)
20
    {
21
        unset($this->list[$name]);
22
    }
23
24
    public function without(...$names)
25
    {
26
        $clone = clone $this;
27
        foreach ($names as $name) {
28
            $clone->remove($name);
29
        }
30
        return $clone;
31
    }
32
33
    public function apply($mapper, $target, $result, ...$args)
34
    {
35
        foreach ($this->list as $behaviour) {
36
            $method = 'on' . Str::className($target);
37
            if (method_exists($behaviour, $method)) {
38
                $result = $behaviour->{$method}($mapper, $result, ...$args);
39
            }
40
        }
41
42
        return $result;
43
    }
44
}
45