File   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 38
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getStream() 0 9 2
A getFilename() 0 3 1
A getContent() 0 5 2
A getMimeType() 0 3 1
1
<?php
2
3
namespace kalanis\RemoteRequest\Protocols\Http\Query;
4
5
6
use kalanis\RemoteRequest\Protocols\Helper;
7
use kalanis\RemoteRequest\RequestException;
8
9
10
/**
11
 * Class File
12
 * @package kalanis\RemoteRequest\Protocols\Http\Query
13
 * Single item for query - file
14
 * Beware: The content must be already loaded into memory, not stay on volume; there is no additional loading (for reasons)
15
 */
16
class File extends Value
17
{
18
    /** @var string|resource */
19
    protected $content = '';
20
    public string $filename = 'binary';
21
    public string $mime = 'octet/stream';
22
23 4
    public function getFilename(): string
24
    {
25 4
        return strval($this->filename);
26
    }
27
28 4
    public function getMimeType(): string
29
    {
30 4
        return strval($this->mime);
31
    }
32
33 3
    public function getContent(): string
34
    {
35 3
        return is_resource($this->content)
36 1
            ? strval(stream_get_contents($this->content, -1, 0))
37 3
            : strval($this->content)
38 3
        ;
39
    }
40
41
    /**
42
     * @throws RequestException
43
     * @return resource
44
     */
45 3
    public function getStream()
46
    {
47 3
        if (is_resource($this->content)) {
48 1
            return $this->content;
49
        }
50 3
        $stream = Helper::getMemStorage();
51 3
        fwrite($stream, strval($this->content));
52 3
        rewind($stream);
53 3
        return $stream;
54
    }
55
}
56