Completed
Push — 2.x ( 8f6930...447f85 )
by Akihito
01:14
created

AssistedInjectMatcher::matchesMethod()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 4
nc 4
nop 2
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 */
0 ignored issues
show
Documentation introduced by
The doc-type list<ReflectionAttribute> could not be parsed: Expected "|" or "end of type", but got "<" at position 4. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
35
            $attributes = $param->getAttributes(InjectInterface::class, ReflectionAttribute::IS_INSTANCEOF);
36
            if (isset($attributes[0])) {
37
                return true;
38
            }
39
40
            /** @var list<ReflectionAttribute> $assisted */
0 ignored issues
show
Documentation introduced by
The doc-type list<ReflectionAttribute> could not be parsed: Expected "|" or "end of type", but got "<" at position 4. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
41
            $assisted = $param->getAttributes(Assisted::class);
42
            if (isset($assisted[0])) {
43
                return true;
44
            }
45
        }
46
47
        return false;
48
    }
49
}
50