Passed
Push — master ( 222a88...547f19 )
by Andrea Marco
02:49 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 1
Bugs 0 Features 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 1
b 0
f 0
1
<?php
2
3
namespace Cerbero\LazyJson;
4
5
use Psr\Http\Message\StreamInterface;
6
7
/**
8
 * The JSON stream wrapper.
9
 *
10
 * @phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
11
 */
12
class StreamWrapper
13
{
14
    /**
15
     * The name of the stream wrapper.
16
     *
17
     * @var string
18
     */
19
    public const NAME = 'cerbero-lazy-json';
20
21
    /**
22
     * The stream context.
23
     *
24
     * @var resource
25
     */
26
    public $context;
27
28
    /**
29
     * The PSR-7 stream.
30
     *
31
     * @var StreamInterface
32
     */
33
    protected $stream;
34
35
    /**
36
     * Open the stream
37
     *
38
     * @param string $path
39
     * @param string $mode
40
     * @param int $options
41
     * @param mixed $opened_path
42
     * @return bool
43
     */
44 10
    public function stream_open(string $path, string $mode, int $options, &$opened_path): bool
0 ignored issues
show
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

44
    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...
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

44
    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 $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

44
    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 $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

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