VendorSpecificJsonHeaderMiddleware::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 3
crap 2
1
<?php
2
3
namespace Thruster\Component\HttpMiddlewares;
4
5
use Psr\Http\Message\ResponseInterface;
6
use Psr\Http\Message\ServerRequestInterface;
7
8
/**
9
 * Class VendorSpecificJsonHeaderMiddleware
10
 *
11
 * @package Thruster\Component\HttpMiddlewares
12
 * @author  Aurimas Niekis <[email protected]>
13
 */
14
class VendorSpecificJsonHeaderMiddleware
15
{
16
    /**
17
     * @var string
18
     */
19
    private $contentType;
20
21 2
    public function __construct(string $contentType)
22
    {
23 2
        $this->contentType = $contentType;
24 2
    }
25
26 2
    public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
27
    {
28 2
        if (false === strpos($response->getHeaderLine('Content-Type'), 'application/json')) {
29 1
            return $next($request, $response);
30
        }
31
32 1
        return $next($request, $response->withHeader('Content-Type', $this->contentType));
33
    }
34
}
35