Completed
Push — master ( 2ca1d3...d53620 )
by Aurimas
12:07
created

VendorSpecificJsonHeaderModifier::modify()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
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
    public function __construct(string $contentType)
22
    {
23
        $this->contentType = $contentType;
24
    }
25
26
    public function modify(ResponseInterface $response) : ResponseInterface
27
    {
28
        if (false === strpos($response->getHeaderLine('Content-Type'), 'application/json')) {
29
            return $response;
30
        }
31
32
        return $response->withHeader('Content-Type', $this->contentType);
33
    }
34
35
}
36