Passed
Push — claude/module-string-evaluatio... ( 60e4d7 )
by Akihito
02:21
created

AopCollector::newInstance()   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
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\Di;
6
7
use LogicException;
8
use Ray\Aop\BindInterface;
9
use Ray\Aop\CompilerInterface;
10
11
use function method_exists;
12
13
/**
14
 * Collects AOP bindings for a dependency
15
 *
16
 * @psalm-import-type PointcutList from Types
17
 * @psalm-type AopBindings = array<string, list<string>>
18
 */
19
final class AopCollector implements CompilerInterface
20
{
21
    /** @var AopBindings */
0 ignored issues
show
Bug introduced by
The type Ray\Di\AopBindings 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...
22
    private array $bindings = [];
23
24
    /**
25
     * @param PointcutList $pointcuts
0 ignored issues
show
Bug introduced by
The type Ray\Di\PointcutList 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...
26
     *
27
     * @return AopBindings
28
     */
29
    public function collect(Dependency $dependency, array $pointcuts): array
30
    {
31
        $this->bindings = [];
0 ignored issues
show
Documentation Bug introduced by
It seems like array() of type array is incompatible with the declared type Ray\Di\AopBindings of property $bindings.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
32
        $dependency->weaveAspects($this, $pointcuts);
33
34
        return $this->bindings;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->bindings returns the type array which is incompatible with the documented return type Ray\Di\AopBindings.
Loading history...
35
    }
36
37
    /**
38
     * {@inheritDoc}
39
     *
40
     * @return never
41
     */
42
    public function newInstance(string $class, array $args, BindInterface $bind)
43
    {
44
        throw new LogicException('AopCollector::newInstance() should never be called');
45
    }
46
47
    /**
48
     * {@inheritDoc}
49
     */
50
    public function compile(string $class, BindInterface $bind): string
51
    {
52
        $bindings = $bind->getBindings();
53
        if (! $bindings) {
0 ignored issues
show
introduced by
$bindings is of type Ray\Aop\MethodBindings, thus it always evaluated to true.
Loading history...
54
            return $class;
55
        }
56
57
        foreach ($bindings as $method => $interceptors) {
58
            if (! method_exists($class, $method)) {
59
                continue;
60
            }
61
62
            /** @var list<string> $interceptors */
63
            $this->bindings[$method] = $interceptors;
64
        }
65
66
        return $class;
67
    }
68
}
69