JsonResponse::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 6
ccs 3
cts 3
cp 1
crap 2
rs 10
c 1
b 0
f 0
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 array<mixed> $json
13
     * @param list<string> $headers
14 4
     */
15
    public function __construct(array $json, array $headers = [])
16 4
    {
17 3
        if (!in_array('Content-Type: application/json', $headers, true)) {
18
            $headers[] = 'Content-Type: application/json';
19 4
        }
20
        parent::__construct(json_encode($json, JSON_THROW_ON_ERROR), $headers);
21
    }
22
}
23