BuildingException::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 13
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 1
nop 4
dl 0
loc 13
ccs 7
cts 7
cp 1
crap 3
rs 10
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