Passed
Push — master ( 7012e0...317384 )
by Rougin
02:29
created

Stream::__toString()   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 0
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 Zapheus\Bridge\Psr\Zapheus;
4
5
use Psr\Http\Message\StreamInterface as PsrStreamInterface;
6
use Zapheus\Http\Message\StreamInterface;
7
8
/**
9
 * PSR-07 to Zapheus Stream Bridge
10
 *
11
 * @package Zapheus
12
 * @author  Rougin Royce Gutib <[email protected]>
13
 */
14
class Stream implements StreamInterface
15
{
16
    /**
17
     * @var \Psr\Http\Message\StreamInterface
18
     */
19
    protected $stream;
20
21
    /**
22
     * Initializes the stream instance.
23
     *
24
     * @param \Psr\Http\Message\StreamInterface $stream
25
     */
26 84
    public function __construct(PsrStreamInterface $stream)
27
    {
28 84
        $this->stream = $stream;
29 84
    }
30
31
    /**
32
     * Reads all data from the stream into a string, from the beginning to end.
33
     *
34
     * @return string
35
     */
36 6
    public function __toString()
37
    {
38 6
        return $this->stream->__toString();
39
    }
40
41
    /**
42
     * Closes the stream and any underlying resources.
43
     *
44
     * @return void
45
     */
46 6
    public function close()
47
    {
48 6
        return $this->stream->close();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->stream->close() targeting Psr\Http\Message\StreamInterface::close() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
49
    }
50
51
    /**
52
     * Returns the remaining contents in a string
53
     *
54
     * @return string
55
     *
56
     * @throws \RuntimeException
57
     */
58 6
    public function contents()
59
    {
60 6
        return $this->stream->getContents();
61
    }
62
63
    /**
64
     * Separates any underlying resources from the stream.
65
     *
66
     * @return resource|null
67
     */
68 6
    public function detach()
69
    {
70 6
        return $this->stream->detach();
71
    }
72
73
    /**
74
     * Returns true if the stream is at the end of the stream.
75
     *
76
     * @return boolean
77
     */
78 3
    public function eof()
79
    {
80 3
        return $this->stream->eof();
81
    }
82
83
    /**
84
     * Get stream metadata as an associative array or retrieve a specific key.
85
     *
86
     * @param  string $key
87
     * @return array|mixed|null
88
     */
89 3
    public function metadata($key = null)
90
    {
91 3
        return $this->stream->getMetadata($key);
92
    }
93
94
    /**
95
     * Read data from the stream.
96
     *
97
     * @param  integer $length
98
     * @return string
99
     *
100
     * @throws \RuntimeException
101
     */
102 6
    public function read($length)
103
    {
104 6
        return $this->stream->read($length);
105
    }
106
107
    /**
108
     * Returns whether or not the stream is readable.
109
     *
110
     * @return boolean
111
     */
112 3
    public function readable()
113
    {
114 3
        return $this->stream->isReadable();
115
    }
116
117
    /**
118
     * Seek to the beginning of the stream.
119
     *
120
     * @throws \RuntimeException
121
     */
122 3
    public function rewind()
123
    {
124 3
        return $this->seek(0);
125
    }
126
127
    /**
128
     * Seek to a position in the stream.
129
     *
130
     * @param integer $offset
131
     * @param integer $whence
132
     *
133
     * @throws \RuntimeException
134
     */
135 9
    public function seek($offset, $whence = SEEK_SET)
136
    {
137 9
        return $this->stream->seek($offset, $whence);
138
    }
139
140
    /**
141
     * Returns whether or not the stream is seekable.
142
     *
143
     * @return boolean
144
     */
145 3
    public function seekable()
146
    {
147 3
        return $this->stream->isSeekable();
148
    }
149
150
    /**
151
     * Get the size of the stream if known.
152
     *
153
     * @return integer|null
154
     */
155 3
    public function size()
156
    {
157 3
        return $this->stream->getSize();
158
    }
159
160
    /**
161
     * Returns the current position of the file read/write pointer.
162
     *
163
     * @return integer
164
     *
165
     * @throws \RuntimeException
166
     */
167 6
    public function tell()
168
    {
169 6
        return $this->stream->tell();
170
    }
171
172
    /**
173
     * Returns whether or not the stream is writable.
174
     *
175
     * @return boolean
176
     */
177 3
    public function writable()
178
    {
179 3
        return $this->stream->isWritable();
180
    }
181
182
    /**
183
     * Write data to the stream.
184
     *
185
     * @param  string $string
186
     * @return integer
187
     *
188
     * @throws \RuntimeException
189
     */
190 6
    public function write($string)
191
    {
192 6
        return $this->stream->write($string);
193
    }
194
}
195