JsonParser   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 26
rs 10
c 2
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
 * JsonParser
19
 *
20
 * @package Slick\Http\Message\Server\BodyParser
21
*/
22
class JsonParser implements BodyParserInterface
23
{
24
    /**
25
     * @var StreamInterface
26
     */
27
    private $stream;
28
29
    /**
30
     * Creates JsonParser
31
     * @param StreamInterface $stream
32
     */
33
    public function __construct(StreamInterface $stream)
34
    {
35
        $this->stream = $stream;
36
    }
37
38
    /**
39
     * Parses the provided
40
     *
41
     * @return mixed
42
     */
43
    public function parse()
44
    {
45
        $this->stream->rewind();
46
        $string = $this->stream->getContents();
47
        return (object) json_decode($string, false);
48
    }
49
}
50