AspectBind   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 13
c 0
b 0
f 0
dl 0
loc 39
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A inject() 0 18 3
A accept() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\Di;
6
7
use Ray\Aop\Bind as AopBind;
8
use Ray\Aop\MethodInterceptor;
9
10
use function assert;
11
12
final class AspectBind implements AcceptInterface
13
{
14
    /** @var AopBind */
15
    private $bind;
16
17
    public function __construct(AopBind $bind)
18
    {
19
        $this->bind = $bind;
20
    }
21
22
    /**
23
     * Instantiate interceptors
24
     *
25
     * @return array<string, array<MethodInterceptor>>
26
     */
27
    public function inject(Container $container): array
28
    {
29
        $bindings = $this->bind->getBindings();
30
        $instantiatedBindings = [];
31
        foreach ($bindings as $methodName => $interceptorClassNames) {
32
            $interceptors = [];
33
            foreach ($interceptorClassNames as $interceptorClassName) {
34
                /** @var class-string $interceptorClassName */
35
                /** @psalm-suppress MixedAssignment */
36
                $interceptor = $container->getInstance($interceptorClassName);
37
                assert($interceptor instanceof MethodInterceptor);
38
                $interceptors[] = $interceptor;
39
            }
40
41
            $instantiatedBindings[$methodName] = $interceptors;
42
        }
43
44
        return $instantiatedBindings;
45
    }
46
47
    /** @inheritDoc */
48
    public function accept(VisitorInterface $visitor)
49
    {
50
        $visitor->visitAspectBind($this->bind);
51
    }
52
}
53