Completed
Push — master ( d10f54...00ced4 )
by
unknown
05:32
created

InjectClass::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 3
cts 3
cp 1
cc 1
eloc 2
nc 1
nop 1
crap 1
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\MethodDefinition;
15
use samsonframework\container\definition\PropertyDefinition;
16
use samsonframework\container\definition\reference\ClassReference;
17
18
/**
19
 * Injection annotation class.
20
 *
21
 * @Annotation
22
 */
23
class InjectClass implements ResolvePropertyInterface, ResolveMethodInterface
24
{
25
    /** @var mixed */
26
    protected $value;
27
28
    /**
29
     * Inject constructor.
30
     *
31
     * @param $value
32
     */
33 2
    public function __construct($value)
34
    {
35 2
        $this->value = $value;
36 2
    }
37
38
    /** {@inheritdoc} */
39 2
    public function resolveProperty(
40
        DefinitionAnalyzer $analyzer,
41
        \ReflectionProperty $reflectionProperty,
42
        ClassDefinition $classDefinition,
43
        PropertyDefinition $propertyDefinition
44
    ) {
45 2
        $propertyDefinition->defineDependency(new ClassReference($this->value['value']));
46 2
    }
47
48
    /**
49
     * {@inheritdoc}
50
     * @throws WrongAnnotationConstructorException
51
     */
52 2
    public function resolveMethod(
53
        DefinitionAnalyzer $analyzer,
54
        \ReflectionMethod $reflectionMethod,
55
        ClassDefinition $classDefinition,
56
        MethodDefinition $methodDefinition
57
    ) {
58
        // Get parameter key
59 2
        $key = array_keys($this->value)[0];
60
        // Add dependency
61 2
        $methodDefinition->defineParameter($key)->defineDependency(new ClassReference($this->value[$key]))->end();
62 2
    }
63
}
64