Failed Conditions
Pull Request — master (#47)
by Florent
12:38
created

FormPostBodyParserMiddleware   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

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 OAuth2Framework\Component\Server\Response\OAuth2Exception;
19
use OAuth2Framework\Component\Server\Response\OAuth2ResponseFactoryManager;
20
use Psr\Http\Message\ServerRequestInterface;
21
22
final class FormPostBodyParserMiddleware implements MiddlewareInterface
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function process(ServerRequestInterface $request, DelegateInterface $delegate)
28
    {
29
        $headers = $request->getHeader('content-type');
30
        foreach ($headers as $header) {
31
            if ('application/x-www-form-urlencoded' === substr($header, 0, 33)) {
32
                $request->getBody()->rewind();
33
                $body = $request->getBody()->getContents();
34
                if (true === parse_str($body, $parsed)) {
35
                    $request = $request->withParsedBody($parsed);
36
                }
37
            }
38
        }
39
40
        return $delegate->process($request);
41
    }
42
}
43