BuildingException   A
last analyzed

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 7
cts 7
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 that don't implement `ContainerExceptionInterface` during the build 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 wasn't found.
19
     * @param string[] $buildStack Stack of IDs of services requested definition or class that wasn't 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 6
            'Caught unhandled error "%s" while building "%s".',
29 6
            $error->getMessage() === '' ? $error::class : $error->getMessage(),
30 6
            implode('" -> "', $buildStack === [] ? [$id] : $buildStack)
31 6
        );
32
33 6
        parent::__construct($message, 0, $previous);
34
    }
35
}
36