Passed
Pull Request — master (#274)
by Dmitriy
02:14
created

NotFoundException   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 25
ccs 11
cts 11
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 2
A getId() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Di;
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
    /**
18
     * @param string $id ID of the definition or name of the class that was not found.
19
     * @param array $buildStack Stack of IDs of services requested definition or class that was not found.
20
     */
21 11
    public function __construct(string $id, array $buildStack = [])
22
    {
23 11
        $this->id = $id;
24
25 11
        $message = $id;
26 11
        if ($buildStack !== []) {
27 7
            $buildStack = array_keys($buildStack);
28 7
            $last = end($buildStack);
29 7
            $message = sprintf('%s while building %s', $last, implode(' -> ', $buildStack));
30
        }
31
32 11
        parent::__construct(sprintf('No definition or class found or resolvable for %s.', $message));
33 11
    }
34
35 1
    public function getId(): string
36
    {
37 1
        return $this->id;
38
    }
39
}
40