VendorSpecificJsonHeaderModifier   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 22
ccs 7
cts 7
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A modify() 0 8 2
1
<?php
2
3
namespace Thruster\Component\HttpModifiers;
4
5
use Psr\Http\Message\ResponseInterface;
6
use Thruster\Component\HttpModifier\ResponseModifierInterface;
7
8
/**
9
 * Class VendorSpecificJsonHeaderModifier
10
 *
11
 * @package Thruster\Component\HttpModifiers
12
 * @author  Aurimas Niekis <[email protected]>
13
 */
14
class VendorSpecificJsonHeaderModifier implements ResponseModifierInterface
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 modify(ResponseInterface $response) : ResponseInterface
27
    {
28 2
        if (false === strpos($response->getHeaderLine('Content-Type'), 'application/json')) {
29 1
            return $response;
30
        }
31
32 1
        return $response->withHeader('Content-Type', $this->contentType);
33
    }
34
35
}
36