Passed
Pull Request — master (#113)
by Dmitriy
03:26
created

PlainTextRenderer::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 2
crap 1
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 1
    public function renderVerbose(Throwable $t, ServerRequestInterface $request = null): ErrorData
23
    {
24 1
        return new ErrorData(
25 1
            self::throwableToString($t)
26 1
        );
27
    }
28
29 15
    public static function throwableToString(Throwable $t): string
30
    {
31 15
        return sprintf(
32 15
            <<<TEXT
33
                %s with message "%s"
34
35
                in %s:%s
36
37
                Stack trace:
38
                %s
39 15
                TEXT,
40 15
            $t::class,
41 15
            $t->getMessage(),
42 15
            $t->getFile(),
43 15
            $t->getLine(),
44 15
            $t->getTraceAsString()
45 15
        );
46
    }
47
}
48