UrlEncodedParser   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 28
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A parse() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of slick/http
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Slick\Http\Message\Server\BodyParser;
13
14
use Psr\Http\Message\StreamInterface;
15
use Slick\Http\Message\Server\BodyParserInterface;
16
17
/**
18
 * UrlEncodedParser
19
 *
20
 * @package Slick\Http\Message\Server\BodyParser
21
*/
22
class UrlEncodedParser implements BodyParserInterface
23
{
24
    /**
25
     * @var StreamInterface
26
     */
27
    private $stream;
28
29
    /**
30
     * Creates an URL Encoded Body Parser
31
     *
32
     * @param StreamInterface $stream
33
     */
34
    public function __construct(StreamInterface $stream)
35
    {
36
        $this->stream = $stream;
37
    }
38
39
    /**
40
     * Parses the URL-encoded body.
41
     *
42
     * @return array<string, mixed>
43
     * @SuppressWarnings(PHPMD)
44
     */
45
    public function parse(): array
46
    {
47
        $this->stream->rewind();
48
        parse_str($this->stream->getContents(), $parsed);
49
        return array_merge($_POST, $parsed);
50
    }
51
}
52