SetJsonResponseHeaders::__invoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 1
rs 10
1
<?php declare(strict_types = 1);
2
3
/**
4
 * This file is part of the Simplex package.
5
 *
6
 * (c) Freddie Frantzen <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Simplex\HttpMiddleware;
12
13
use Psr\Http\Message\ResponseInterface as Response;
14
use Psr\Http\Message\ServerRequestInterface;
15
16
final class SetJsonResponseHeaders
17
{
18
    public const ACCEPT_HEADER_NAME = 'accept';
19
    public const ACCEPT_HEADER_VALUE = 'application/json';
20
21
    public const CONTENT_TYPE_HEADER_NAME = 'content-type';
22
    public const CONTENT_TYPE_HEADER_VALUE = 'application/json';
23
24 2
    public function __invoke(ServerRequestInterface $request, Response $response, callable $next)
25
    {
26
        /** @var Response $response */
27 2
        $response = $next($request, $response);
28
29
        return $response
30 2
            ->withHeader(self::ACCEPT_HEADER_NAME, self::ACCEPT_HEADER_VALUE)
31 2
            ->withHeader(self::CONTENT_TYPE_HEADER_NAME, self::CONTENT_TYPE_HEADER_VALUE);
32
    }
33
}
34