CumulativeException   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A getExceptions() 0 3 1
A getMessageDetails() 0 16 2
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