SetJsonResponseHeaders   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 16
ccs 4
cts 4
cp 1
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 8 1
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