Completed
Push — master ( 7ed063...7400f3 )
by Andrea Marco
05:20 queued 12s
created

StreamWrapper::stream_read()   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 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Cerbero\JsonObjects;
4
5
use Psr\Http\Message\StreamInterface;
6
7
/**
8
 * The stream wrapper.
9
 *
10
 */
11
class StreamWrapper
12
{
13
    /**
14
     * The name of the stream wrapper.
15
     *
16
     * @var string
17
     */
18
    const NAME = 'cerbero-json-objects';
19
20
    /**
21
     * The stream context.
22
     *
23
     * @var resource
24
     */
25
    public $context;
26
27
    /**
28
     * The stream.
29
     *
30
     * @var \Psr\Http\Message\StreamInterface
31
     */
32
    protected $stream;
33
34
    /**
35
     * Open the stream
36
     *
37
     * @param string $path
38
     * @param string $mode
39
     * @param int $options
40
     * @param mixed $opened_path
41
     * @return bool
42
     */
43 24
    public function stream_open(string $path, string $mode, int $options, &$opened_path) : bool
1 ignored issue
show
Unused Code introduced by
The parameter $options is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

43
    public function stream_open(string $path, string $mode, /** @scrutinizer ignore-unused */ int $options, &$opened_path) : bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opened_path is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

43
    public function stream_open(string $path, string $mode, int $options, /** @scrutinizer ignore-unused */ &$opened_path) : bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $path is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

43
    public function stream_open(/** @scrutinizer ignore-unused */ string $path, string $mode, int $options, &$opened_path) : bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $mode is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

43
    public function stream_open(string $path, /** @scrutinizer ignore-unused */ string $mode, int $options, &$opened_path) : bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
44
    {
45 24
        $options = stream_context_get_options($this->context);
46 24
        $stream = $options[static::NAME]['stream'] ?? null;
47
48 24
        if (!$stream instanceof StreamInterface || !$stream->isReadable()) {
49 9
            return false;
50
        }
51
52 15
        $this->stream = $stream;
53
54 15
        return true;
55
    }
56
57
    /**
58
     * Determine whether the pointer is at the end of the stream
59
     *
60
     * @return bool
61
     */
62 6
    public function stream_eof() : bool
63
    {
64 6
        return $this->stream->eof();
65
    }
66
67
    /**
68
     * Read from the stream
69
     *
70
     * @param int $count
71
     * @return string
72
     */
73 3
    public function stream_read(int $count) : string
74
    {
75 3
        return $this->stream->read($count);
76
    }
77
}
78