Completed
Push — master ( fcdf89...4a0ecc )
by Alexander
14:58
created

ThrowableRenderer::setRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
namespace Yiisoft\Yii\Web\ErrorHandler;
3
4
use Psr\Http\Message\ServerRequestInterface;
5
6
abstract class ThrowableRenderer implements ThrowableRendererInterface
7
{
8
    private const SEVERITY_NAMES = [
9
        E_COMPILE_ERROR => 'PHP Compile Error',
10
        E_COMPILE_WARNING => 'PHP Compile Warning',
11
        E_CORE_ERROR => 'PHP Core Error',
12
        E_CORE_WARNING => 'PHP Core Warning',
13
        E_DEPRECATED => 'PHP Deprecated Warning',
14
        E_ERROR => 'PHP Fatal Error',
15
        E_NOTICE => 'PHP Notice',
16
        E_PARSE => 'PHP Parse Error',
17
        E_RECOVERABLE_ERROR => 'PHP Recoverable Error',
18
        E_STRICT => 'PHP Strict Warning',
19
        E_USER_DEPRECATED => 'PHP User Deprecated Warning',
20
        E_USER_ERROR => 'PHP User Error',
21
        E_USER_NOTICE => 'PHP User Notice',
22
        E_USER_WARNING => 'PHP User Warning',
23
        E_WARNING => 'PHP Warning',
24
    ];
25
26
    /**
27
     * @var ServerRequestInterface
28
     */
29
    protected $request;
30
31
    protected function getThrowableName(\Throwable $t)
32
    {
33
        $name = get_class($t);
34
35
        if ($t instanceof \ErrorException && isset(self::SEVERITY_NAMES[$t->getSeverity()])) {
36
            $name .= ' (' . self::SEVERITY_NAMES[$t->getSeverity()] . ')';
37
        }
38
39
        return $name;
40
    }
41
42
    protected function convertThrowableToVerboseString(\Throwable $t): string
43
    {
44
        $message = $this->getThrowableName($t) . "with message '{$t->getMessage()}' \n\nin "
45
            . $t->getFile() . ':' . $t->getLine() . "\n\n"
46
            . "Stack trace:\n" . $t->getTraceAsString();
47
        return $message;
48
    }
49
50
    public function setRequest(ServerRequestInterface $request): void
51
    {
52
        $this->request = $request;
53
    }
54
}
55