AspectBind::inject()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 17
rs 9.9332
cc 3
nc 3
nop 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
/**
13
 * @psalm-import-type MethodInterceptorBindings from Types
14
 */
15
final class AspectBind implements AcceptInterface
16
{
17
    public function __construct(private AopBind $bind)
18
    {
19
    }
20
21
    /**
22
     * Instantiate interceptors
23
     *
24
     * @return MethodInterceptorBindings
0 ignored issues
show
Bug introduced by
The type Ray\Di\MethodInterceptorBindings was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
     */
26
    public function inject(Container $container): array
27
    {
28
        $bindings = $this->bind->getBindings();
29
        $instantiatedBindings = [];
30
        foreach ($bindings as $methodName => $interceptorClassNames) {
31
            $interceptors = [];
32
            foreach ($interceptorClassNames as $interceptorClassName) {
33
                /** @var class-string $interceptorClassName */
34
                $interceptor = $container->getInstance($interceptorClassName);
35
                assert($interceptor instanceof MethodInterceptor);
36
                $interceptors[] = $interceptor;
37
            }
38
39
            $instantiatedBindings[$methodName] = $interceptors;
40
        }
41
42
        return $instantiatedBindings;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $instantiatedBindings returns the type array which is incompatible with the documented return type Ray\Di\MethodInterceptorBindings.
Loading history...
43
    }
44
45
    /** @inheritDoc */
46
    public function accept(VisitorInterface $visitor): void
47
    {
48
        $visitor->visitAspectBind($this->bind);
49
    }
50
}
51