MethodService   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
dl 0
loc 51
ccs 21
cts 21
cp 1
rs 10
c 1
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getDependencies() 0 8 2
A findDependencies() 0 7 2
A getAnnotationParameters() 0 9 2
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cekta\DI\Reflection;
6
7
use ReflectionMethod;
8
9
/**
10
 * @internal
11
 */
12
class MethodService
13
{
14
    /**
15
     * @var ParameterService
16 15
     */
17
    private $parameter;
18 15
19 15
    public function __construct()
20
    {
21
        $this->parameter = new ParameterService();
22
    }
23
    /**
24 9
     * @param ReflectionMethod|null $method
25
     * @return array<string>
26 9
     */
27 9
    public function findDependencies(?ReflectionMethod $method): array
28 6
    {
29
        $parameters = [];
30 9
        if ($method !== null) {
31
            $parameters = $this->getDependencies($method);
32
        }
33
        return $parameters;
34
    }
35
36
    /**
37 6
     * @param string $comment
38
     * @return array<string>
39 6
     */
40 6
    private function getAnnotationParameters(string $comment): array
41 6
    {
42 6
        $result = [];
43 3
        $matches = [];
44
        preg_match_all("/@inject \\\\?([\w\d\\\\]*) \\$([\w\d]*)/", $comment, $matches, PREG_SET_ORDER);
45 6
        foreach ($matches as $match) {
46
            $result[$match[2]] = $match[1];
47
        }
48
        return $result;
49
    }
50
51
    /**
52 6
     * @param ReflectionMethod $method
53
     * @return array<string>
54 6
     */
55 6
    private function getDependencies(ReflectionMethod $method): array
56 6
    {
57 6
        $parameters = [];
58
        $annotations = $this->getAnnotationParameters((string) $method->getDocComment());
59 6
        foreach ($method->getParameters() as $parameter) {
60
            $parameters[] = $this->parameter->getName($parameter, $annotations);
61
        }
62
        return $parameters;
63
    }
64
}
65