|
24 | 24 | use function is_resource; |
25 | 25 | use function is_string; |
26 | 26 | use function sprintf; |
| 27 | +use function str_contains; |
27 | 28 | use function stream_get_contents; |
28 | 29 | use function stream_get_meta_data; |
29 | | -use function strstr; |
30 | 30 |
|
31 | 31 | use const SEEK_SET; |
32 | 32 |
|
@@ -210,11 +210,11 @@ public function isWritable(): bool |
210 | 210 | $meta = stream_get_meta_data($this->resource); |
211 | 211 | $mode = $meta['mode']; |
212 | 212 |
|
213 | | - return strstr($mode, 'x') !== false |
214 | | - || strstr($mode, 'w') !== false |
215 | | - || strstr($mode, 'c') !== false |
216 | | - || strstr($mode, 'a') !== false |
217 | | - || strstr($mode, '+') !== false; |
| 213 | + return str_contains($mode, 'x') |
| 214 | + || str_contains($mode, 'w') |
| 215 | + || str_contains($mode, 'c') |
| 216 | + || str_contains($mode, 'a') |
| 217 | + || str_contains($mode, '+'); |
218 | 218 | } |
219 | 219 |
|
220 | 220 | /** |
@@ -251,7 +251,7 @@ public function isReadable(): bool |
251 | 251 | $meta = stream_get_meta_data($this->resource); |
252 | 252 | $mode = $meta['mode']; |
253 | 253 |
|
254 | | - return strstr($mode, 'r') !== false || strstr($mode, '+') !== false; |
| 254 | + return str_contains($mode, 'r') || str_contains($mode, '+'); |
255 | 255 | } |
256 | 256 |
|
257 | 257 | /** |
@@ -297,11 +297,15 @@ public function getContents(): string |
297 | 297 | */ |
298 | 298 | public function getMetadata(?string $key = null) |
299 | 299 | { |
| 300 | + $metadata = []; |
| 301 | + if (null !== $this->resource) { |
| 302 | + $metadata = stream_get_meta_data($this->resource); |
| 303 | + } |
| 304 | + |
300 | 305 | if (null === $key) { |
301 | | - return stream_get_meta_data($this->resource); |
| 306 | + return $metadata; |
302 | 307 | } |
303 | 308 |
|
304 | | - $metadata = stream_get_meta_data($this->resource); |
305 | 309 | if (! array_key_exists($key, $metadata)) { |
306 | 310 | return null; |
307 | 311 | } |
|
0 commit comments