Passed
Push — master ( f184eb...e0b5ba )
by Dmitriy
09:27 queued 06:41
created

BuildingException   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 3
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 6
    public function __construct(
22
        string $id,
23
        Throwable $error,
24
        array $buildStack = [],
25
        Throwable $previous = null,
26
    ) {
27 6
        $message = sprintf(
28
            'Caught unhandled error "%s" while building "%s".',
29 6
            $error->getMessage() === '' ? $error::class : $error->getMessage(),
30 6
            implode('" -> "', $buildStack === [] ? [$id] : $buildStack)
31
        );
32
33 6
        parent::__construct($message, 0, $previous);
34
    }
35
}
36