Test Failed
Pull Request — master (#316)
by Alexander
07:57 queued 05:10
created

BuildingException   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 21
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Di;
6
7
use Exception;
8
use Psr\Container\ContainerExceptionInterface;
9
use Throwable;
10
11
/**
12
 * It wraps all exceptions which do not implement ContainerExceptionInterface while building process.
13
 * Also adds building context for more understanding.
14
 */
15
final class BuildingException extends Exception implements ContainerExceptionInterface
16
{
17
    /**
18
     * @param string $id ID of the definition or name of the class that was not found.
19
     * @param string[] $buildStack Stack of IDs of services requested definition or class that was not found.
20
     */
21
    public function __construct(
22
        string $id,
23
        string $error,
24
        array $buildStack = [],
25
        Throwable $previous = null,
26
    ) {
27
        $message = sprintf('Caught unhandled error "%s" while building "%s"', $error, $id);
28
29
        if ($buildStack !== []) {
30
            $message .= '"' . implode('" -> "', $buildStack) . '"';
31
        }
32
33
        $message .= '.';
34
35
        parent::__construct($message, 0, $previous);
36
    }
37
}
38