Passed
Push — visitor ( 2d5566 )
by Akihito
11:02
created

AspectBind::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
nc 1
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
use Ray\Compiler\CompileVisitor;
0 ignored issues
show
Bug introduced by
The type Ray\Compiler\CompileVisitor 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...
10
11
use function assert;
12
13
final class AspectBind
14
{
15
    /** @var AopBind */
16
    private $bind;
17
18
    public function __construct(AopBind $bind)
19
    {
20
        $this->bind = $bind;
21
    }
22
23
    /**
24
     * Instantiate interceptors
25
     *
26
     * @return array<string, array<MethodInterceptor>>
27
     */
28
    public function inject(Container $container): array
29
    {
30
        $bindings = $this->bind->getBindings();
31
        $instantiatedBindings = [];
32
        foreach ($bindings as $methodName => $interceptorClassNames) {
33
            $interceptors = [];
34
            foreach ($interceptorClassNames as $interceptorClassName) {
35
                /** @var class-string $interceptorClassName */
36
                /** @psalm-suppress MixedAssignment */
37
                $interceptor = $container->getInstance($interceptorClassName);
38
                assert($interceptor instanceof MethodInterceptor);
39
                $interceptors[] = $interceptor;
40
            }
41
42
            $instantiatedBindings[$methodName] = $interceptors;
43
        }
44
45
        return $instantiatedBindings;
46
    }
47
48
    public function accept(VisitorInterface $visitor)
49
    {
50
        assert($visitor instanceof CompileVisitor);
51
        $visitor->visitAspectBind($this->bind);
0 ignored issues
show
Bug introduced by
The method visitAspectBind() does not exist on Ray\Di\VisitorInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

51
        $visitor->/** @scrutinizer ignore-call */ 
52
                  visitAspectBind($this->bind);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
52
    }
53
}
54