Failed Conditions
Pull Request — master (#47)
by Florent
16:41 queued 12:22
created

FormPostBodyParserMiddleware   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 21
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 15 4
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2017 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace OAuth2Framework\Component\Server\Middleware;
15
16
use Interop\Http\ServerMiddleware\DelegateInterface;
17
use Interop\Http\ServerMiddleware\MiddlewareInterface;
18
use Psr\Http\Message\ServerRequestInterface;
19
20
final class FormPostBodyParserMiddleware implements MiddlewareInterface
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function process(ServerRequestInterface $request, DelegateInterface $delegate)
26
    {
27
        $headers = $request->getHeader('content-type');
28
        foreach ($headers as $header) {
29
            if ('application/x-www-form-urlencoded' === substr($header, 0, 33)) {
30
                $request->getBody()->rewind();
31
                $body = $request->getBody()->getContents();
32
                if (true === parse_str($body, $parsed)) {
33
                    $request = $request->withParsedBody($parsed);
34
                }
35
            }
36
        }
37
38
        return $delegate->process($request);
39
    }
40
}
41