Passed
Pull Request — master (#817)
by Maxim
06:18
created

ContainerException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 9
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 4
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Core\Exception\Container;
6
7
use Psr\Container\ContainerExceptionInterface;
8
use Spiral\Core\Exception\RuntimeException;
9
10
/**
11
 * Something inside container.
12
 */
13
class ContainerException extends RuntimeException implements ContainerExceptionInterface
14
{
15 452
    public function __construct(
16
        string $message = '',
17
        int $code = 0,
18
        ?\Throwable $previous = null,
19
        protected array &$trace = []
20
    ) {
21 452
        parent::__construct($this->addTrace($message), $code, $previous);
22
23 452
        $trace = [];
24
    }
25
26 452
    protected function addTrace(string $message): string
27
    {
28 452
        $result = [];
29 452
        $result[] = $message;
30
31 452
        if ($this->trace !== []) {
32 409
            $result[] = 'Container stack trace:';
33
34 409
            foreach ($this->trace as $item) {
35 409
                $result[] = $item;
36
            }
37
        }
38
39 452
        return \implode(PHP_EOL, $result);
40
    }
41
}
42