Completed
Branch develop (85a9c8)
by Anton
05:44
created

Context::getName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
namespace Spiral\Core\Container;
9
10
/**
11
 * Provided to method or constructor which declares such dependency.
12
 */
13
final class Context
14
{
15
    /**
16
     * @var \ReflectionFunctionAbstract
17
     */
18
    private $function = null;
19
20
    /**
21
     * @var \ReflectionParameter|null
22
     */
23
    private $parameter = null;
24
25
    /**
26
     * @param \ReflectionFunctionAbstract $function
27
     * @param \ReflectionParameter|null   $parameter
28
     */
29
    public function __construct(
30
        \ReflectionFunctionAbstract $function,
31
        \ReflectionParameter $parameter = null
32
    ) {
33
        $this->function = $function;
34
        $this->parameter = $parameter;
35
    }
36
37
    /**
38
     * Function or method or constructor.
39
     *
40
     * @return \ReflectionFunctionAbstract
41
     */
42
    public function getFunction()
43
    {
44
        return $this->function;
45
    }
46
47
    /**
48
     * Can be empty.
49
     *
50
     * @return null|\ReflectionParameter
51
     */
52
    public function getParameter()
53
    {
54
        return $this->parameter;
55
    }
56
57
    /**
58
     * @return string|null
59
     */
60
    public function getName()
61
    {
62
        if (empty($this->parameter)) {
63
            return null;
64
        }
65
66
        return $this->parameter->getName();
67
    }
68
}