Passed
Push — master ( 1045ee...ba70cb )
by Sergei
02:38
created

NotFoundException::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.2109

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 4
b 0
f 0
nc 2
nop 2
dl 0
loc 12
ccs 5
cts 8
cp 0.625
crap 2.2109
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Definitions\Exception;
6
7
use Exception;
8
use Psr\Container\NotFoundExceptionInterface;
9
10
/**
11
 * NotFoundException is thrown when no definition or class was found in the container for a given ID.
12
 */
13
final class NotFoundException extends Exception implements NotFoundExceptionInterface
14
{
15
    private string $id;
16
17 2
    public function __construct(string $id, array $buildStack = [])
18
    {
19 2
        $this->id = $id;
20
21 2
        $message = $id;
22 2
        if ($buildStack !== []) {
23
            $buildStack = array_keys($buildStack);
24
            $last = end($buildStack);
25
            $message = sprintf('%s while building %s', $last, implode(' -> ', $buildStack));
26
        }
27
28 2
        parent::__construct(sprintf('No definition or class found or resolvable for %s.', $message));
29 2
    }
30
31 1
    public function getId(): string
32
    {
33 1
        return $this->id;
34
    }
35
}
36