Completed
Push — master ( 48a801...d2a888 )
by Changwan
03:14
created

CannotResolveException::getCallee()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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