Completed
Push — master ( 9fe7e8...7331b7 )
by Aurimas
12:47
created

JsonBodyParser::parse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 6

Duplication

Lines 14
Ratio 100 %
Metric Value
dl 14
loc 14
rs 9.4286
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
3
namespace Thruster\Component\Http\Parser;
4
5
use Psr\Http\Message\ServerRequestInterface;
6
7
/**
8
 * Class JsonBodyParser
9
 *
10
 * @package Thruster\Component\Http\Parser
11
 * @author  Aurimas Niekis <[email protected]>
12
 */
13 View Code Duplication
class JsonBodyParser implements ParserInterface
0 ignored issues
show
Duplication introduced by
This class 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...
14
{
15
    /**
16
     * @inheritDoc
17
     */
18
    public function parse(ServerRequestInterface $request) : ServerRequestInterface
19
    {
20
        if (false === strpos($request->getHeaderLine('Content-Type'), 'application/json')) {
21
            return $request;
22
        }
23
24
        $body = $request->getBody()->getContents();
25
26
        $parsedBody = json_decode($body, true);
27
28
        // TODO: Implement broken json handling
29
30
        return $request->withParsedBody($parsedBody);
31
    }
32
}
33