RequirePackageException::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 2
dl 0
loc 10
ccs 0
cts 10
cp 0
crap 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace Wandu\DI\Exception;
3
4
use Psr\Container\NotFoundExceptionInterface;
5
use RuntimeException;
6
7
class RequirePackageException extends RuntimeException implements NotFoundExceptionInterface
8
{
9
    /** @var string */
10
    protected $class;
11
12
    /** @var string */
13
    protected $package;
14
15
    /**
16
     * @param string $class
17
     * @param string $package
18
     */
19
    public function __construct($class, $package)
20
    {
21
        $traces = debug_backtrace();
22
        $this->message = "cannot find the \"{$class}\" class, install \"{$package}\" package.";
23
        $this->package = $package;
24
        if (isset($traces[1])) {
25
            $this->file = $traces[1]['file'];
26
            $this->line = $traces[1]['line'];
27
        }
28
    }
29
30
    /**
31
     * @return string
32
     */
33
    public function getClass()
34
    {
35
        return $this->class;
36
    }
37
38
    /**
39
     * @return string
40
     */
41
    public function getPackage()
42
    {
43
        return $this->package;
44
    }
45
}
46