PhpInputStream   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 21
ccs 8
cts 8
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A copyInput() 0 11 1
1
<?php declare(strict_types=1);
2
3
/**
4
 * It's free open-source software released under the MIT License.
5
 *
6
 * @author Anatoly Nekhay <[email protected]>
7
 * @copyright Copyright (c) 2018, Anatoly Nekhay
8
 * @license https://github.com/sunrise-php/http-message/blob/master/LICENSE
9
 * @link https://github.com/sunrise-php/http-message
10
 */
11
12
namespace Sunrise\Http\Message\Stream;
13
14
use Sunrise\Http\Message\Stream;
15
16
use function fopen;
17
use function fseek;
18
use function stream_copy_to_stream;
19
20
use const SEEK_SET;
21
22
final class PhpInputStream extends Stream
23
{
24 39
    public function __construct()
25
    {
26 39
        parent::__construct(self::copyInput());
27
    }
28
29
    /**
30
     * @return resource
31
     */
32 39
    private static function copyInput()
33
    {
34
        /** @var resource $input */
35 39
        $input = fopen('php://input', 'rb');
36
        /** @var resource $resource */
37 39
        $resource = fopen('php://temp', 'r+b');
38
39 39
        stream_copy_to_stream($input, $resource);
40 39
        fseek($resource, 0, SEEK_SET);
41
42 39
        return $resource;
43
    }
44
}
45