Passed
Push — master ( 8d5c50...f86379 )
by Alexander
01:44
created

CumulativeException   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 90.48%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getMessageDetails() 0 16 2
A getExceptions() 0 3 1
A __construct() 0 6 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Cycle\Exception;
6
7
use RuntimeException;
8
use Throwable;
9
10
class CumulativeException extends RuntimeException
11
{
12
    /** @var Throwable[] */
13
    private array $exceptions;
14
15 1
    public function __construct(Throwable ...$exceptions)
16
    {
17 1
        $this->exceptions = $exceptions;
18 1
        $count = count($exceptions);
19 1
        $message = $count === 1 ? 'One exception was thrown.' : $count . ' exceptions were thrown.';
20 1
        parent::__construct($message . $this->getMessageDetails());
21 1
    }
22
23
    /**
24
     * @return Throwable[]
25
     */
26
    public function getExceptions(): array
27
    {
28
        return $this->exceptions;
29
    }
30
31 1
    private function getMessageDetails(): string
32
    {
33 1
        $result = '';
34 1
        $num = 0;
35 1
        foreach ($this->exceptions as $exception) {
36 1
            $result .= sprintf(
37 1
                "\n\n%d) %s:%s\n[%s] #%d: %s",
38 1
                ++$num,
39 1
                $exception->getFile(),
40 1
                $exception->getLine(),
41 1
                get_class($exception),
42 1
                $exception->getCode(),
43 1
                $exception->getMessage()
44
            );
45
        }
46 1
        return $result;
47
    }
48
}
49