StreamWrapper::stream_eof()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Cerbero\JsonParser\Sources;
4
5
use Psr\Http\Message\StreamInterface;
6
7
/**
8
 * The JSON stream wrapper.
9
 *
10
 * @codeCoverageIgnore
11
 * @phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
12
 */
13
final class StreamWrapper
14
{
15
    /**
16
     * The name of the stream wrapper.
17
     *
18
     * @var string
19
     */
20
    public const NAME = 'cerbero-json-parser';
21
22
    /**
23
     * The stream context.
24
     *
25
     * @var resource
26
     */
27
    public mixed $context;
28
29
    /**
30
     * The PSR-7 stream.
31
     *
32
     * @var StreamInterface
33
     */
34
    private $stream;
35
36
    /**
37
     * Open the stream
38
     *
39
     * @param string $path
40
     * @param string $mode
41
     * @param int $options
42
     * @param mixed $opened_path
43
     * @return bool
44
     *
45
     * @scrutinizer ignore-unused
46
     */
47
    public function stream_open(string $path, string $mode, int $options, &$opened_path): bool
48
    {
49
        $options = stream_context_get_options($this->context);
50
51
        $this->stream = $options[self::NAME]['stream'] ?? null;
52
53
        return $this->stream instanceof StreamInterface && $this->stream->isReadable();
54
    }
55
56
    /**
57
     * Determine whether the pointer is at the end of the stream
58
     *
59
     * @return bool
60
     */
61
    public function stream_eof(): bool
62
    {
63
        return $this->stream->eof();
64
    }
65
66
    /**
67
     * Read from the stream
68
     *
69
     * @param int $count
70
     * @return string
71
     */
72
    public function stream_read(int $count): string
73
    {
74
        return $this->stream->read($count);
75
    }
76
}
77