Completed
Push — master ( 00ced4...d3edd8 )
by
unknown
07:54
created

InjectService::resolveProperty()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
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\ServiceReference;
21
22
/**
23
 * Injection annotation service.
24
 *
25
 * @Annotation
26
 */
27
class InjectService implements ResolvePropertyInterface, ResolveMethodInterface
28
{
29
    /** @var mixed */
30
    protected $value;
31
32
    /**
33
     * Inject constructor.
34
     *
35
     * @param $value
36
     */
37
    public function __construct($value)
38
    {
39
        $this->value = $value;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     * @throws PropertyDefinitionNotFoundException
45
     */
46
    public function resolveProperty(
47
        DefinitionAnalyzer $analyzer,
48
        ClassDefinition $classDefinition,
49
        \ReflectionProperty $reflectionProperty
50
    ) {
51
        $propertyName = $reflectionProperty->getName();
52
        if ($classDefinition->hasProperty($propertyName)) {
53
            $classDefinition->getProperty($propertyName)
54
                ->defineDependency(new ServiceReference($this->value['value']));
55
        }
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     * @throws WrongAnnotationConstructorException
61
     * @throws MethodDefinitionNotFoundException
62
     * @throws ParameterDefinitionAlreadyExistsException
63
     * @throws MethodDefinitionAlreadyExistsException
64
     */
65 View Code Duplication
    public function resolveMethod(
0 ignored issues
show
Duplication introduced by
This method 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...
66
        DefinitionAnalyzer $analyzer,
67
        ClassDefinition $classDefinition,
68
        \ReflectionMethod $reflectionMethod
69
    ) {
70
        // Get parameter key
71
        $key = array_keys($this->value)[0];
72
        $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...
73
            ->defineParameter($key)
74
            ->defineDependency(new ServiceReference($this->value[$key]))->end();
75
    }
76
}
77