HtmlErrorRenderer::response()   A
last analyzed

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
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Conia\Chuck\Renderer;
6
7
use Conia\Chuck\Error\Error;
8
use Conia\Chuck\Factory;
9
use Conia\Chuck\Response;
10
11
/** @psalm-api */
12
class HtmlErrorRenderer implements Renderer
13
{
14 5
    public function __construct(protected Factory $factory)
15
    {
16 5
    }
17
18 4
    public function render(mixed $data, mixed ...$args): string
19
    {
20 4
        assert(is_array($data));
21 4
        assert(isset($data['error']));
22 4
        assert($data['error'] instanceof Error);
23 4
        $error = $data['error'];
24
25 4
        $title = htmlspecialchars($error->error);
26
27 4
        return sprintf(
28 4
            '<!doctype html>' .
29 4
            '<html lang="en">' .
30 4
            '<head>' .
31 4
            '<meta charset="utf-8">' .
32 4
            '<meta name="viewport" content="width=device-width, initial-scale=1">' .
33 4
            '<title>%s</title>' .
34 4
            '</head>' .
35 4
            '<body><h1>%s</h1></body></html>',
36 4
            $title,
37 4
            $title
38 4
        );
39
    }
40
41 4
    public function response(mixed $data, mixed ...$args): Response
42
    {
43 4
        return Response::fromFactory($this->factory)->html($this->render($data));
44
    }
45
}
46