GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

JsonStream::read()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Middleware\Json;
4
5
use ApiClients\Foundation\Transport\ParsedContentsInterface;
6
use Psr\Http\Message\StreamInterface;
7
use RingCentral\Psr7\BufferStream;
8
9
class JsonStream implements StreamInterface, ParsedContentsInterface
10
{
11
    /**
12
     * @var array
13
     */
14
    private $json = [];
15
16
    /**
17
     * @var StreamInterface
18
     */
19
    private $bufferStream;
20
21 6
    public function __construct(array $json)
22
    {
23 6
        $this->json = $json;
24 6
        $jsonString = \json_encode($json);
25 6
        $this->bufferStream = new BufferStream(\strlen($jsonString));
26 6
        $this->bufferStream->write($jsonString);
27 6
    }
28
29
    public function __toString()
30
    {
31
        return $this->getContents();
32
    }
33
34
    /**
35
     * @return array
36
     */
37 6
    public function getParsedContents(): array
38
    {
39 6
        return $this->json;
40
    }
41
42 1
    public function getContents()
43
    {
44 1
        return $this->bufferStream->getContents();
45
    }
46
47
    public function close(): void
48
    {
49
    }
50
51
    public function detach(): void
52
    {
53
    }
54
55 1
    public function getSize()
56
    {
57 1
        return $this->bufferStream->getSize();
58
    }
59
60
    public function isReadable()
61
    {
62
        return $this->bufferStream->isReadable();
63
    }
64
65
    public function isWritable()
66
    {
67
        return $this->bufferStream->isWritable();
68
    }
69
70
    public function isSeekable()
71
    {
72
        return $this->bufferStream->isSeekable();
73
    }
74
75
    public function rewind()
76
    {
77
        return $this->bufferStream->rewind();
78
    }
79
80
    public function seek($offset, $whence = \SEEK_SET)
81
    {
82
        return $this->bufferStream->seek($offset, $whence);
83
    }
84
85
    public function eof()
86
    {
87
        return $this->bufferStream->eof();
88
    }
89
90
    public function tell()
91
    {
92
        return $this->bufferStream->tell();
93
    }
94
95
    /**
96
     * Reads data from the buffer.
97
     * @param mixed $length
98
     */
99
    public function read($length)
100
    {
101
        return $this->bufferStream->read($length);
102
    }
103
104
    /**
105
     * Writes data to the buffer.
106
     * @param mixed $string
107
     */
108
    public function write($string)
109
    {
110
        return $this->bufferStream->write($string);
111
    }
112
113
    public function getMetadata($key = null)
114
    {
115
        return $this->bufferStream->getMetadata($key);
116
    }
117
}
118