Test Failed
Push — lazy-services ( 2f8c8b...8212a3 )
by Dmitriy
16:14 queued 13:07
created

NotFoundException::getId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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
    /**
16
     * @param string $id ID of the definition or name of the class that was not found.
17
     * @param string[] $buildStack Stack of IDs of services requested definition or class that was not found.
18
     */
19
    public function __construct(
20
        private string $id,
21
        array $buildStack = []
22
    ) {
23
        $message = $id;
24
        if ($buildStack !== []) {
25
            $last = end($buildStack);
26
            $message = sprintf('%s" while building %s', $last, '"' . implode('" -> "', $buildStack));
27
        }
28
29
        parent::__construct(sprintf('No definition or class found or resolvable for "%s".', $message));
30
    }
31
32
    public function getId(): string
33
    {
34
        return $this->id;
35
    }
36
}
37