1 | <?php |
||
35 | class BufferStream implements Streamable |
||
36 | { |
||
37 | use IsReadable, IsWritable; |
||
38 | |||
39 | /** |
||
40 | * Buffer contents |
||
41 | * @var string A string containing the buffer contents |
||
42 | */ |
||
43 | protected $buffer = ''; |
||
44 | |||
45 | /** |
||
46 | * Is stream readable? |
||
47 | * |
||
48 | * @var boolean Whether stream is readable |
||
49 | */ |
||
50 | protected $readable = true; |
||
51 | |||
52 | /** |
||
53 | * Is stream writable? |
||
54 | * |
||
55 | * @var boolean Whether stream is writable |
||
56 | */ |
||
57 | protected $writable = true; |
||
58 | |||
59 | /** |
||
60 | * Is stream seekable? |
||
61 | * |
||
62 | * @var boolean Whether stream is seekable |
||
63 | */ |
||
64 | protected $seekable = false; |
||
65 | |||
66 | /** |
||
67 | * @var array Stream meta data |
||
68 | * hwm: "high water mark" - once buffer reaches this number (in bytes) |
||
69 | * write() operations will begin returning false defaults to 16384 bytes (16KB) |
||
70 | */ |
||
71 | protected $meta = [ |
||
72 | 'hwm' => 16384 |
||
73 | ]; |
||
74 | |||
75 | /** |
||
76 | * Instantiate a buffer stream. |
||
77 | * |
||
78 | * Instantiate a new buffer stream, optionally changing the high water mark |
||
79 | * from its default of 16384 bytes (16KB). Once buffer reaches high water |
||
80 | * mark, write operations will begin returning false. It's possible for buffer |
||
81 | * size to exceed this level since it is only AFTER it is reached that writes |
||
82 | * begin returning false. |
||
83 | * |
||
84 | * @param int Number (in bytes) representing buffer "high water mark" |
||
85 | */ |
||
86 | 31 | public function __construct($hwm = null) |
|
87 | { |
||
88 | 31 | if (!is_null($hwm)) { |
|
89 | 9 | $this->meta['hwm'] = $hwm; |
|
90 | 9 | } |
|
91 | 31 | } |
|
92 | |||
93 | 12 | public function isEmpty() |
|
97 | |||
98 | 12 | public function isFull() |
|
102 | |||
103 | /** |
||
104 | * Readability accessor. |
||
105 | * |
||
106 | * Despite the fact that any class that implements this interface must also |
||
107 | * define methods such as read and readLine, that is no guarantee that an |
||
108 | * object will necessarily be readable. This method should tell the user |
||
109 | * whether a stream is, in fact, readable. |
||
110 | * |
||
111 | * @return boolean True if readable, false otherwise |
||
112 | */ |
||
113 | 1 | public function isReadable() |
|
117 | |||
118 | /** |
||
119 | * Read in the specified amount of characters from the input source |
||
120 | * |
||
121 | * @param integer Amount of characters to read from input source |
||
122 | * @return string|boolean The specified amount of characters read from input source |
||
123 | */ |
||
124 | 18 | public function read($chars) |
|
128 | |||
129 | /** |
||
130 | * Read a chunk of buffer data. |
||
131 | * |
||
132 | * Removes a specific chunk of data from the buffer and return it. |
||
133 | * |
||
134 | * @param int|null $start |
||
135 | * @param int|null $length |
||
136 | * @return string The chunk of data read from the buffer |
||
137 | */ |
||
138 | 19 | public function readChunk($start = null, $length = null) |
|
148 | |||
149 | /** |
||
150 | * Read the entire stream, beginning to end. |
||
151 | * |
||
152 | * In most stream implementations, __toString() differs from getContents() |
||
153 | * in that it returns the entire stream rather than just the remainder, but |
||
154 | * due to the way this stream works (sort of like a conveyor belt), this |
||
155 | * method is an alias to getContents() |
||
156 | * |
||
157 | * @return string The entire stream, beginning to end |
||
158 | */ |
||
159 | public function __toString() |
||
163 | |||
164 | /** |
||
165 | * Read the remainder of the stream |
||
166 | * |
||
167 | * @return string The remainder of the stream |
||
168 | */ |
||
169 | 3 | public function getContents() |
|
175 | |||
176 | /** |
||
177 | * Return the size (in bytes) of this readable (if known). |
||
178 | * |
||
179 | * @return int|null Size (in bytes) of this readable |
||
180 | */ |
||
181 | 21 | public function getSize() |
|
185 | |||
186 | /** |
||
187 | * Return the current position within the stream/readable |
||
188 | * |
||
189 | * @return int The current position within readable |
||
190 | */ |
||
191 | 2 | public function tell() |
|
195 | |||
196 | /** |
||
197 | * Determine whether the end of the readable resource has been reached |
||
198 | * |
||
199 | * @return boolean Whether we're at the end of the readable |
||
200 | */ |
||
201 | 6 | public function eof() |
|
205 | |||
206 | /** |
||
207 | * File must be able to be rewound when the end is reached |
||
208 | */ |
||
209 | 3 | public function rewind() |
|
213 | |||
214 | /** |
||
215 | * Get stream metadata as an associative array or retrieve a specific key. |
||
216 | * |
||
217 | * The keys returned are identical to the keys returned from PHP's |
||
218 | * stream_get_meta_data() function. |
||
219 | * |
||
220 | * @param string $key Specific metadata to retrieve. |
||
221 | * @return array|mixed|null Returns an associative array if no key is |
||
222 | * provided. Returns a specific key value if a key is provided and the |
||
223 | * value is found, or null if the key is not found. |
||
224 | * @see http://php.net/manual/en/function.stream-get-meta-data.php |
||
225 | */ |
||
226 | 22 | public function getMetadata($key = null) |
|
233 | |||
234 | /** |
||
235 | * Closes the stream and any underlying resources. |
||
236 | * |
||
237 | * @return void |
||
238 | */ |
||
239 | 2 | public function close() |
|
243 | |||
244 | /** |
||
245 | * Separates any underlying resources from the stream. |
||
246 | * |
||
247 | * After the stream has been detached, the stream is in an unusable state. |
||
248 | * |
||
249 | * @return string|null Underlying PHP stream, if any |
||
250 | */ |
||
251 | 1 | public function detach() |
|
257 | |||
258 | /** |
||
259 | * Writability accessor. |
||
260 | * |
||
261 | * Despite the fact that any class that implements this interface must also |
||
262 | * define methods such as write and writeLine, that is no guarantee that an |
||
263 | * object will necessarily be writable. This method should tell the user |
||
264 | * whether a stream is, in fact, writable. |
||
265 | * |
||
266 | * @return boolean True if writable, false otherwise |
||
267 | */ |
||
268 | 1 | public function isWritable() |
|
272 | |||
273 | /** |
||
274 | * Write data to the output. |
||
275 | * |
||
276 | * @param string The data to write |
||
277 | * @return int The number of bytes written |
||
278 | */ |
||
279 | 21 | public function write($data) |
|
287 | |||
288 | /** |
||
289 | * Seekability accessor. |
||
290 | * |
||
291 | * Despite the fact that any class that implements this interface must also |
||
292 | * define methods such as seek, that is no guarantee that an |
||
293 | * object will necessarily be seekable. This method should tell the user |
||
294 | * whether a stream is, in fact, seekable. |
||
295 | * |
||
296 | * @return boolean True if seekable, false otherwise |
||
297 | */ |
||
298 | 1 | public function isSeekable() |
|
302 | |||
303 | /** |
||
304 | * Seek to specified offset. |
||
305 | * |
||
306 | * @param integer Offset to seek to |
||
307 | * @param integer Position from whence the offset should be applied |
||
308 | * @return boolean True if seek was successful |
||
309 | */ |
||
310 | 1 | public function seek($offset, $whence = SEEK_SET) |
|
314 | |||
315 | } |
||
316 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.