@@ -24,14 +24,14 @@ class Stream implements StreamInterface
24
24
private const READABLE_MATCH = '/r|a\+|ab\+|w\+|wb\+|x\+|xb\+|c\+|cb\+/ ' ;
25
25
private const WRITABLE_MATCH = '/a|w|r\+|rb\+|rw|x|c/ ' ;
26
26
27
- private $ stream ;
28
- private $ permission ;
29
- private $ resource ;
30
- private $ size ;
31
- private $ meta = array () ;
32
- private $ readable ;
33
- private $ writable ;
34
- private $ seekable ;
27
+ private mixed $ stream ;
28
+ private string $ permission ;
29
+ private mixed $ resource ;
30
+ private ? int $ size = null ;
31
+ private array $ meta ;
32
+ private bool $ readable ;
33
+ private bool $ writable ;
34
+ private bool $ seekable ;
35
35
36
36
/**
37
37
* PSR-7 Stream
@@ -47,11 +47,11 @@ public function __construct(mixed $stream = null, string $permission = "r+")
47
47
if (is_resource ($ stream )) {
48
48
$ this ->resource = $ stream ;
49
49
$ this ->meta = $ this ->getMetadata ();
50
-
51
- if (is_null ($ this ->meta )) {
52
- throw new RuntimeException ("Could not access the stream meta data . " , 1 );
50
+ /*
51
+ if (is_null($this->meta)) {
52
+ throw new RuntimeException("Could not access the stream metadata .", 1);
53
53
}
54
-
54
+ */
55
55
$ this ->stream = $ this ->meta ['stream_type ' ];
56
56
$ this ->permission = $ this ->meta ['mode ' ];
57
57
} else {
@@ -112,7 +112,7 @@ public function detach()
112
112
}
113
113
114
114
/**
115
- * Returns whether or not the stream is seekable.
115
+ * Returns whether the stream is seekable.
116
116
* @return bool
117
117
*/
118
118
public function isSeekable (): bool
@@ -121,7 +121,7 @@ public function isSeekable(): bool
121
121
}
122
122
123
123
/**
124
- * Returns whether or not the stream is writable.
124
+ * Returns whether the stream is writable.
125
125
* @return bool
126
126
*/
127
127
public function isWritable (): bool
@@ -130,7 +130,7 @@ public function isWritable(): bool
130
130
}
131
131
132
132
/**
133
- * Returns whether or not the stream is readable.
133
+ * Returns whether the stream is readable.
134
134
* @return bool
135
135
*/
136
136
public function isReadable (): bool
@@ -159,14 +159,14 @@ public function stats(?string $key = null): mixed
159
159
public function getSize (): ?int
160
160
{
161
161
$ size = $ this ->stats ('size ' );
162
- $ this ->size = isset ( $ size) ? $ size : null ;
162
+ $ this ->size = $ size ?? null ;
163
163
return $ this ->size ;
164
164
}
165
165
166
166
/**
167
167
* Returns the current position of the file read/write pointer
168
168
* @return int Position of the file pointer
169
- * @throws \ RuntimeException on error.
169
+ * @throws RuntimeException on error.
170
170
*/
171
171
public function tell (): int
172
172
{
@@ -189,7 +189,7 @@ public function getLine(): string|bool
189
189
*/
190
190
public function eof (): bool
191
191
{
192
- return (is_resource ($ this ->resource )) ? feof ($ this ->resource ) : true ;
192
+ return ! (is_resource ($ this ->resource )) || feof ($ this ->resource );
193
193
}
194
194
195
195
/**
@@ -210,24 +210,24 @@ public function clean(): void
210
210
* PHP $whence values for `fseek()`. SEEK_SET: Set position equal to
211
211
* offset bytes SEEK_CUR: Set position to current location plus offset
212
212
* SEEK_END: Set position to end-of-stream plus offset.
213
- * @throws \ RuntimeException on failure.
213
+ * @throws RuntimeException on failure.
214
214
*/
215
215
public function seek ($ offset , $ whence = SEEK_SET ): void
216
216
{
217
217
if ($ this ->isSeekable ()) {
218
218
fseek ($ this ->resource , $ offset , $ whence );
219
219
} else {
220
- throw new RuntimeException ("The stream \"{ $ this ->stream } ( { $ this ->permission } ) \" is not seekable! " , 1 );
220
+ throw new RuntimeException ("The stream \"$ this ->stream ( $ this ->permission ) \" is not seekable! " , 1 );
221
221
}
222
222
}
223
223
224
224
/**
225
225
* Seek to the beginning of the stream.
226
226
* If the stream is not seekable, this method will raise an exception;
227
227
* otherwise, it will perform a seek(0).
228
+ * @throws RuntimeException on failure.
229
+ *@link http://www.php.net/manual/en/function.fseek.php
228
230
* @see seek()
229
- * @link http://www.php.net/manual/en/function.fseek.php
230
- * @throws \RuntimeException on failure.
231
231
*/
232
232
public function rewind (): void
233
233
{
@@ -244,8 +244,7 @@ public function write(string $string): int
244
244
if (is_null ($ this ->size )) {
245
245
$ this ->size = 0 ;
246
246
}
247
- $ byte = fwrite ($ this ->resource , $ string );
248
- return $ byte ;
247
+ return fwrite ($ this ->resource , $ string );
249
248
}
250
249
251
250
/**
@@ -264,7 +263,7 @@ public function read(int $length): string
264
263
/**
265
264
* Returns the remaining contents in a string
266
265
* @return string
267
- * @throws \ RuntimeException if unable to read or an error occurs while reading.
266
+ * @throws RuntimeException if unable to read or an error occurs while reading.
268
267
*/
269
268
public function getContents (): string
270
269
{
@@ -276,7 +275,7 @@ public function getContents(): string
276
275
277
276
/**
278
277
* Get stream metadata as an associative array or retrieve a specific key.
279
- * @param string $key Specific metadata to retrieve.
278
+ * @param string|null $key Specific metadata to retrieve.
280
279
* @return array|mixed|null Returns an associative array
281
280
*/
282
281
public function getMetadata (?string $ key = null ): mixed
@@ -305,7 +304,7 @@ public function withContext(array $opts): StreamInterface
305
304
* Open a resource correct with the right resource
306
305
* @param ...$fArgs
307
306
* @return false|resource
308
- * @throws \ RuntimeException on error.
307
+ * @throws RuntimeException on error.
309
308
*/
310
309
private function fopen (...$ fArgs )
311
310
{
0 commit comments