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

ThrowableRenderer::getThrowableName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

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 9
ccs 4
cts 5
cp 0.8
crap 2.032
rs 10
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