AssistedInjectMatcher   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 11
dl 0
loc 33
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A matchesClass() 0 3 1
A matchesMethod() 0 18 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\Di\Matcher;
6
7
use LogicException;
8
use Ray\Aop\AbstractMatcher;
9
use Ray\Di\Di\Assisted;
10
use Ray\Di\Di\InjectInterface;
11
use ReflectionAttribute;
12
use ReflectionClass;
13
use ReflectionMethod;
14
15
final class AssistedInjectMatcher extends AbstractMatcher
16
{
17
    /**
18
     * {@inheritdoc}
19
     *
20
     * @codeCoverageIgnore
21
     */
22
    public function matchesClass(ReflectionClass $class, array $arguments): bool
23
    {
24
        throw new LogicException('Should not used in class matcher');
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function matchesMethod(ReflectionMethod $method, array $arguments): bool
31
    {
32
        $params = $method->getParameters();
33
        foreach ($params as $param) {
34
            /** @var list<ReflectionAttribute> $attributes */
35
            $attributes = $param->getAttributes(InjectInterface::class, ReflectionAttribute::IS_INSTANCEOF);
36
            if (isset($attributes[0])) {
37
                return true;
38
            }
39
40
            /** @var list<ReflectionAttribute> $assisted */
41
            $assisted = $param->getAttributes(Assisted::class);
42
            if (isset($assisted[0])) {
43
                return true;
44
            }
45
        }
46
47
        return false;
48
    }
49
}
50