ParseJsonRequestBodyModifier::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Thruster\Component\HttpModifiers;
4
5
use Psr\Http\Message\ServerRequestInterface;
6
use Thruster\Component\HttpModifier\ServerRequestModifierInterface;
7
8
/**
9
 * Class ParseJsonRequestBodyModifier
10
 *
11
 * @package Thruster\Component\HttpModifiers\ResponseModifier
12
 * @author  Aurimas Niekis <[email protected]>
13
 */
14
class ParseJsonRequestBodyModifier implements ServerRequestModifierInterface
15
{
16
    /**
17
     * @var bool
18
     */
19
    private $asAssociativeArray;
20
21 2
    public function __construct(bool $asAssociativeArray = true)
22
    {
23 2
        $this->asAssociativeArray = $asAssociativeArray;
24 2
    }
25
26 2 View Code Duplication
    public function modify(ServerRequestInterface $request) : ServerRequestInterface
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
    {
28 2
        if (false === strpos($request->getHeaderLine('Content-Type'), 'application/json')) {
29
            return $request;
30
        }
31
32
        // TODO: Implement broken json handling
33
34 2
        return $request->withParsedBody(json_decode($request->getBody()->getContents(), $this->asAssociativeArray));
35
    }
36
37
}
38