Passed
Push — master ( b86ef6...5fed0d )
by Alexander
02:39
created

ThrowableRenderer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 25
ccs 10
cts 11
cp 0.9091
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getThrowableName() 0 9 2
A setRequest() 0 3 1
A convertThrowableToVerboseString() 0 5 1
1
<?php
2
3
namespace Yiisoft\Yii\Web\ErrorHandler;
4
5
use Psr\Http\Message\ServerRequestInterface;
6
use Yiisoft\FriendlyException\FriendlyExceptionInterface;
7
8
abstract class ThrowableRenderer implements ThrowableRendererInterface
9
{
10
    protected ?ServerRequestInterface $request = null;
11
12 6
    protected function getThrowableName(\Throwable $t): string
13
    {
14 6
        $name = get_class($t);
15
16 6
        if ($t instanceof FriendlyExceptionInterface) {
17
            $name = $t->getName() . ' (' . $name . ')';
18
        }
19
20 6
        return $name;
21
    }
22
23 5
    protected function convertThrowableToVerboseString(\Throwable $t): string
24
    {
25 5
        return $this->getThrowableName($t) . " with message '{$t->getMessage()}' \n\nin "
26 5
            . $t->getFile() . ':' . $t->getLine() . "\n\n"
27 5
            . "Stack trace:\n" . $t->getTraceAsString();
28
    }
29
30 8
    public function setRequest(ServerRequestInterface $request): void
31
    {
32 8
        $this->request = $request;
33 8
    }
34
}
35