InjectionPoints   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 14
dl 0
loc 52
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addMethod() 0 5 1
A getSetterMethod() 0 8 2
A __invoke() 0 8 2
A addOptionalMethod() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\Di;
6
7
use ReflectionException;
8
use ReflectionMethod;
9
10
/**
11
 * @psalm-import-type InjectionPointDefinition from Types
12
 * @psalm-import-type InjectionPointsList from Types
13
 */
14
final class InjectionPoints
15
{
16
    /**
17
     * Injection points
18
     *
19
     * @var InjectionPointsList
0 ignored issues
show
Bug introduced by
The type Ray\Di\InjectionPointsList 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...
20
     */
21
    private $points = [];
22
23
    /**
24
     * @param class-string $class
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string.
Loading history...
25
     *
26
     * @throws ReflectionException
27
     */
28
    public function __invoke(string $class): SetterMethods
29
    {
30
        $points = [];
31
        foreach ($this->points as $point) {
32
            $points[] = $this->getSetterMethod($class, $point);
33
        }
34
35
        return new SetterMethods($points);
36
    }
37
38
    public function addMethod(string $method, string $name = Name::ANY): self
39
    {
40
        $this->points[] = [$method, $name, false];
41
42
        return $this;
43
    }
44
45
    public function addOptionalMethod(string $method, string $name = Name::ANY): self
46
    {
47
        $this->points[] = [$method, $name, true];
48
49
        return $this;
50
    }
51
52
    /**
53
     * @param class-string             $class
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string.
Loading history...
54
     * @param InjectionPointDefinition $point
55
     *
56
     * @throws ReflectionException
57
     */
58
    private function getSetterMethod(string $class, array $point): SetterMethod
59
    {
60
        $setterMethod = new SetterMethod(new ReflectionMethod($class, $point[0]), new Name($point[1]));
61
        if ($point[2]) {
62
            $setterMethod->setOptional();
63
        }
64
65
        return $setterMethod;
66
    }
67
}
68