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

URLEncodedBodyParser   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2
Metric Value
wmc 2
lcom 0
cbo 2
dl 18
loc 18
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A parse() 12 12 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Thruster\Component\Http\Parser;
4
5
use Psr\Http\Message\ServerRequestInterface;
6
7
/**
8
 * Class URLEncodedBodyParser
9
 *
10
 * @package Thruster\Component\Http\Parser
11
 * @author  Aurimas Niekis <[email protected]>
12
 */
13 View Code Duplication
class URLEncodedBodyParser 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/x-www-form-urlencoded')) {
21
            return $request;
22
        }
23
24
        $body = $request->getBody()->getContents();
25
26
        parse_str($body, $parsedBody);
27
28
        return $request->withParsedBody($parsedBody);
29
    }
30
}
31