TextErrorRenderer::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 0
dl 0
loc 2
ccs 1
cts 1
cp 1
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 1
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 TextErrorRenderer implements Renderer
13
{
14 2
    public function __construct(protected Factory $factory)
15
    {
16 2
    }
17
18 1
    public function render(mixed $data, mixed ...$args): string
19
    {
20 1
        assert(is_array($data));
21 1
        assert(isset($data['error']));
22 1
        assert($data['error'] instanceof Error);
23 1
        $error = $data['error'];
24
25 1
        return "Error: {$error->error}";
26
    }
27
28 1
    public function response(mixed $data, mixed ...$args): Response
29
    {
30 1
        return Response::fromFactory($this->factory)->text($this->render($data));
31
    }
32
}
33