Passed
Push — master ( edb799...f409da )
by Petr
07:56
created

Helper::getTempStorage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
3
namespace kalanis\RemoteRequest\Protocols;
4
5
6
use kalanis\RemoteRequest\RequestException;
7
8
9
/**
10
 * Class Helper
11
 * @package kalanis\RemoteRequest\Protocols
12
 */
13
class Helper
14
{
15
    /**
16
     * @throws RequestException
17
     * @return resource
18
     */
19 17
    public static function getTempStorage()
20
    {
21 17
        return static::getStorageResource('php://temp');
22
    }
23
24
    /**
25
     * @throws RequestException
26
     * @return resource
27
     */
28 26
    public static function getMemStorage()
29
    {
30 26
        return static::getStorageResource('php://memory');
31
    }
32
33
    /**
34
     * @param string $path
35
     * @throws RequestException
36
     * @return resource
37
     */
38 36
    protected static function getStorageResource(string $path)
39
    {
40 36
        $res = fopen($path, 'rw');
41 36
        if (false === $res) {
42
            // @codeCoverageIgnoreStart
43
            throw new RequestException('Cannot open temporary storage!');
44
        }
45
        // @codeCoverageIgnoreEnd
46 36
        rewind($res);
47 36
        return $res;
48
    }
49
}
50