Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
41 / 41
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
LegacyDevelopment
100.00% covered (success)
100.00%
41 / 41
100.00% covered (success)
100.00%
3 / 3
8
100.00% covered (success)
100.00%
1 / 1
 render
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
1 / 1
1
 formatStackTrace
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
1 / 1
5
 getDisplayNameOfValue
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace Engelsystem\Exceptions\Handlers;
6
7use Engelsystem\Http\Request;
8use Throwable;
9
10class LegacyDevelopment extends Legacy
11{
12    public function render(Request $request, Throwable $e): void
13    {
14        $file = $this->stripBasePath($e->getFile());
15
16        echo sprintf(
17            '<pre style="%s">',
18            'background-color:#333;color:#ccc;z-index:1000;position:fixed;'
19            . 'bottom:1em;padding:1em;width:97%;max-height:90%;overflow-y:auto;'
20        );
21        echo sprintf('%s: (%s)' . PHP_EOL, get_class($e), $e->getCode());
22        $data = [
23            'string'     => $e->getMessage(),
24            'file'       => $file . ':' . $e->getLine(),
25            'stacktrace' => $this->formatStackTrace($e->getTrace()),
26        ];
27
28        ob_start(function (string $buffer) {
29            return htmlspecialchars($buffer);
30        });
31        var_dump($data);
32        ob_end_flush();
33
34        echo '</pre>';
35    }
36
37    protected function formatStackTrace(array $stackTrace): array
38    {
39        $return = [];
40        $stackTrace = array_reverse($stackTrace);
41
42        foreach ($stackTrace as $trace) {
43            $path = '';
44            $line = '';
45
46            if (isset($trace['file']) && isset($trace['line'])) {
47                $path = $this->stripBasePath($trace['file']);
48                $line = $trace['line'];
49            }
50
51            $functionName = $trace['function'];
52
53            $args = [];
54            foreach (($trace['args'] ?? []) as $arg) {
55                $args[] = $this->getDisplayNameOfValue($arg);
56            }
57
58            $return[] = [
59                'file'        => $path . ':' . $line,
60                $functionName => $args,
61            ];
62        }
63
64        return $return;
65    }
66
67    private function getDisplayNameOfValue(mixed $arg): string
68    {
69        return match (gettype($arg)) {
70            'string', 'integer', 'double' => (string) $arg,
71            'boolean'  => $arg ? 'true' : 'false',
72            'object'   => get_class($arg),
73            'resource' => get_resource_type($arg), // @codeCoverageIgnore
74            default    => gettype($arg),
75        };
76    }
77}