CumulativeException::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\Schema\Provider\Exception;
6
7
final class CumulativeException extends \RuntimeException
8
{
9
    /**
10
     * @var array<\Throwable>
11
     */
12
    private array $exceptions;
13
14 6
    public function __construct(\Throwable ...$exceptions)
15
    {
16 6
        $this->exceptions = $exceptions;
17 6
        $count = count($exceptions);
18 6
        $message = $count === 1 ? 'One exception was thrown.' : $count . ' exceptions were thrown.';
19 6
        parent::__construct($message . $this->getMessageDetails());
20
    }
21
22
    /**
23
     * @return array<\Throwable>
24
     */
25 1
    public function getExceptions(): array
26
    {
27 1
        return $this->exceptions;
28
    }
29
30 6
    private function getMessageDetails(): string
31
    {
32 6
        $result = '';
33 6
        $num = 0;
34 6
        foreach ($this->exceptions as $exception) {
35 5
            $result .= \sprintf(
36 5
                "\n\n%d) %s:%s\n[%s] #%d: %s",
37 5
                ++$num,
38 5
                $exception->getFile(),
39 5
                $exception->getLine(),
40 5
                \get_class($exception),
41 5
                $exception->getCode(),
42 5
                $exception->getMessage()
43 5
            );
44
        }
45 6
        return $result;
46
    }
47
}
48