Passed
Pull Request — master (#277)
by Kirill
03:11
created

ArgumentException::getParameter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Core\Exception\Container;
13
14
use ReflectionFunctionAbstract;
15
use ReflectionMethod;
16
use ReflectionParameter;
17
18
/**
19
 * Unable to resolve argument value.
20
 */
21
class ArgumentException extends AutowireException
22
{
23
    /**
24
     * Parameter caused error.
25
     *
26
     * @var ReflectionParameter
27
     */
28
    protected $parameter;
29
30
    /**
31
     * Context method or constructor or function.
32
     *
33
     * @var ReflectionFunctionAbstract
34
     */
35
    protected $context;
36
37
    /**
38
     * @param ReflectionParameter        $parameter
39
     * @param ReflectionFunctionAbstract $context
40
     */
41
    public function __construct(ReflectionParameter $parameter, ReflectionFunctionAbstract $context)
42
    {
43
        $this->parameter = $parameter;
44
        $this->context = $context;
45
46
        $name = $context->getName();
47
        if ($context instanceof ReflectionMethod) {
48
            $name = $context->class . '::' . $name;
49
        }
50
51
        parent::__construct("Unable to resolve '{$parameter->name}' argument in '{$name}'");
52
    }
53
54
    /**
55
     * @return ReflectionParameter
56
     */
57
    public function getParameter(): ReflectionParameter
58
    {
59
        return $this->parameter;
60
    }
61
62
    /**
63
     * @return ReflectionFunctionAbstract
64
     */
65
    public function getContext(): ReflectionFunctionAbstract
66
    {
67
        return $this->context;
68
    }
69
}
70