Completed
Push — master ( b31514...603a9f )
by Changwan
06:16
created

CannotResolveException::getCallee()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Wandu\DI\Exception;
3
4
use Psr\Container\NotFoundExceptionInterface;
5
use RuntimeException;
6
use ReflectionClass;
7
use Wandu\Reflection\ReflectionCallable;
8
9
class CannotResolveException extends RuntimeException implements NotFoundExceptionInterface
10
{
11
    /** @var string */
12
    protected $class;
13
    
14
    /** @var callable */
15
    protected $callee;
16
17
    /** @var string */
18
    protected $parameter;
19
20
    /**
21
     * @param string $classOrCallee
22
     * @param string $parameter
23
     */
24 12
    public function __construct($classOrCallee, $parameter)
25
    {
26 12
        if (is_string($classOrCallee) && (class_exists($classOrCallee) || interface_exists($classOrCallee))) {
27 8
            $this->class = $classOrCallee;
28 8
            $refl = new ReflectionClass($classOrCallee);
29 8
            $this->file = $refl->getFileName();
30 8
            if ($propRefl = $refl->getConstructor()) {
31 8
                $this->line = $propRefl->getStartLine();
32
            } else {
33
                $this->line = $refl->getStartLine();
34
            }
35 8
            $this->message = "cannot resolve the \"{$parameter}\" parameter in the \"{$classOrCallee}\" class.";
36 4
        } elseif (is_callable($classOrCallee)) {
37 4
            $this->callee = $classOrCallee;
38 4
            $refl = new ReflectionCallable($classOrCallee);
39 4
            $this->line = $refl->getStartLine();
40 4
            $this->file = $refl->getFileName();
41 4
            $this->message = "cannot resolve the \"{$parameter}\" parameter in the {$refl->getCallableName()}.";
42
        }
43 12
        $this->parameter = $parameter;
44 12
    }
45
46
    /**
47
     * @return string
48
     */
49
    public function getClass()
50
    {
51
        return $this->class;
52
    }
53
54
    /**
55
     * @return callable
56
     */
57
    public function getCallee()
58
    {
59
        return $this->callee;
60
    }
61
62
    /**
63
     * @return string
64
     */
65 10
    public function getParameter()
66
    {
67 10
        return $this->parameter;
68
    }
69
}
70