Test Failed
Pull Request — master (#113)
by Alexander
04:45 queued 02:11
created

PlainTextRenderer::throwableToString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 16
ccs 0
cts 0
cp 0
rs 9.9666
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\ErrorHandler\Renderer;
6
7
use Psr\Http\Message\ServerRequestInterface;
8
use Throwable;
9
use Yiisoft\ErrorHandler\ErrorData;
10
use Yiisoft\ErrorHandler\ThrowableRendererInterface;
11
12
/**
13
 * Formats throwable into plain text string.
14
 */
15
final class PlainTextRenderer implements ThrowableRendererInterface
16
{
17 7
    public function render(Throwable $t, ServerRequestInterface $request = null): ErrorData
18
    {
19 7
        return new ErrorData(self::DEFAULT_ERROR_MESSAGE);
20
    }
21
22 15
    public function renderVerbose(Throwable $t, ServerRequestInterface $request = null): ErrorData
23
    {
24 15
        return new ErrorData(
25 15
            self::throwableToString($t)
26 15
        );
27 15
    }
28 15
29
    public static function throwableToString(Throwable $t): string
30
    {
31
        return sprintf(
32
            <<<TEXT
33
                %s with message "%s"
34
35
                in %s:%s
36
37
                Stack trace:
38
                %s
39
                TEXT,
40
            $t::class,
41
            $t->getMessage(),
42
            $t->getFile(),
43
            $t->getLine(),
44
            $t->getTraceAsString()
45
        );
46
    }
47
}
48