Completed
Push — master ( d3edd8...61bf89 )
by
unknown
02:52
created

InjectParameter::resolveMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 3
1
<?php declare(strict_types = 1);
2
/**
3
 * Created by Ruslan Molodyko.
4
 * Date: 10.09.2016
5
 * Time: 15:33
6
 */
7
namespace samsonframework\container\definition\analyzer\annotation\annotation;
8
9
use samsonframework\container\definition\analyzer\annotation\ResolveMethodInterface;
10
use samsonframework\container\definition\analyzer\annotation\ResolvePropertyInterface;
11
use samsonframework\container\definition\analyzer\DefinitionAnalyzer;
12
use samsonframework\container\definition\analyzer\exception\WrongAnnotationConstructorException;
13
use samsonframework\container\definition\ClassDefinition;
14
use samsonframework\container\definition\exception\MethodDefinitionAlreadyExistsException;
15
use samsonframework\container\definition\exception\MethodDefinitionNotFoundException;
16
use samsonframework\container\definition\exception\ParameterDefinitionAlreadyExistsException;
17
use samsonframework\container\definition\exception\PropertyDefinitionNotFoundException;
18
use samsonframework\container\definition\MethodDefinition;
19
use samsonframework\container\definition\PropertyDefinition;
20
use samsonframework\container\definition\reference\ParameterReference;
21
use samsonframework\container\definition\reference\ServiceReference;
22
23
/**
24
 * Injection annotation parameter.
25
 *
26
 * @Annotation
27
 */
28 View Code Duplication
class InjectParameter implements ResolvePropertyInterface, ResolveMethodInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
{
30
    /** @var mixed */
31
    protected $value;
32
33
    /**
34
     * Inject constructor.
35
     *
36
     * @param $value
37
     */
38
    public function __construct($value)
39
    {
40
        $this->value = $value;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     * @throws PropertyDefinitionNotFoundException
46
     */
47
    public function resolveProperty(
48
        DefinitionAnalyzer $analyzer,
49
        ClassDefinition $classDefinition,
50
        \ReflectionProperty $reflectionProperty
51
    ) {
52
        $propertyName = $reflectionProperty->getName();
53
        if ($classDefinition->hasProperty($propertyName)) {
54
            $classDefinition->getProperty($propertyName)
55
                ->defineDependency(new ParameterReference($this->value['value']));
56
        }
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     * @throws WrongAnnotationConstructorException
62
     * @throws MethodDefinitionNotFoundException
63
     * @throws ParameterDefinitionAlreadyExistsException
64
     * @throws MethodDefinitionAlreadyExistsException
65
     */
66
    public function resolveMethod(
67
        DefinitionAnalyzer $analyzer,
68
        ClassDefinition $classDefinition,
69
        \ReflectionMethod $reflectionMethod
70
    ) {
71
        // Get parameter key
72
        $key = array_keys($this->value)[0];
73
        $classDefinition->setupMethod($reflectionMethod->getName())
0 ignored issues
show
Bug introduced by
Consider using $reflectionMethod->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
74
            ->defineParameter($key)
75
                ->defineDependency(new ParameterReference($this->value[$key]))
76
            ->end();
77
    }
78
}
79