Passed
Pull Request — master (#27)
by Anatoly
39:10
created

PhpTempStream   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 18
ccs 3
cts 4
cp 0.75
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
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
/**
15
 * Import classes
16
 */
17
use Sunrise\Http\Message\Exception\InvalidArgumentException;
18
use Sunrise\Http\Message\Stream;
19
20
/**
21
 * Import functions
22
 */
23
use function fopen;
24
use function sprintf;
25
26
/**
27
 * @link https://www.php.net/manual/en/wrappers.php.php#wrappers.php.memory
28
 */
29
class PhpTempStream extends Stream
30
{
31
32
    /**
33
     * Constructor of the class
34
     *
35
     * @param string $mode
36
     * @param int $maxmemory
37
     *
38
     * @throws InvalidArgumentException
39
     */
40 39
    public function __construct(string $mode = 'r+b', int $maxmemory = 2097152)
41
    {
42 39
        if ($maxmemory < 0) {
43
            throw new InvalidArgumentException('Argument #2 ($maxmemory) must be greater than or equal to 0');
44
        }
45
46 39
        parent::__construct(fopen(sprintf('php://temp/maxmemory:%d', $maxmemory), $mode));
47
    }
48
}
49