Passed
Push — main ( 2aad05...56c0cb )
by Chema
53s queued 13s
created

JsonResponse::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Router\Entities;
6
7
use function in_array;
8
9
final class JsonResponse extends Response
10
{
11
    /**
12
     * @param list<string> $headers
13
     */
14 2
    public function __construct(array $json, array $headers = [])
15
    {
16 2
        if (!in_array('Content-Type: application/json', $headers, true)) {
17 1
            $headers[] = 'Content-Type: application/json';
18
        }
19 2
        parent::__construct(json_encode($json, JSON_THROW_ON_ERROR), $headers);
20
    }
21
}
22