Skip to content

Commit 56c14a1

Browse files
authored
Use Hyperf\Collection\Collection instead of Hyperf\Utils\Collection. (#5593)
* Format code * Use `Hyperf\Collection\Collection` instead of `Hyperf\Utils\Collection`. * Use `Hyperf\Collection\collect` instead of `collect`.
1 parent a6593ec commit 56c14a1

File tree

1 file changed

+33
-18
lines changed

1 file changed

+33
-18
lines changed

src/Stream/StandardStream.php

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@
1616
use Psr\Http\Message\StreamInterface;
1717
use RuntimeException;
1818

19+
use function clearstatcache;
20+
use function fclose;
21+
use function feof;
22+
use function fopen;
23+
use function fread;
24+
use function fseek;
25+
use function fstat;
26+
use function ftell;
27+
use function fwrite;
28+
use function is_resource;
29+
use function is_string;
30+
use function stream_get_contents;
31+
use function stream_get_meta_data;
32+
use function var_export;
33+
1934
use const SEEK_CUR;
2035
use const SEEK_SET;
2136

@@ -100,17 +115,17 @@ public static function create($body = ''): StreamInterface
100115
return $body;
101116
}
102117

103-
if (\is_string($body)) {
104-
$resource = \fopen('php://temp', 'rw+');
105-
\fwrite($resource, $body);
118+
if (is_string($body)) {
119+
$resource = fopen('php://temp', 'rw+');
120+
fwrite($resource, $body);
106121
$body = $resource;
107122
}
108123

109-
if (\is_resource($body)) {
124+
if (is_resource($body)) {
110125
$new = new self();
111126
$new->stream = $body;
112-
$meta = \stream_get_meta_data($new->stream);
113-
$new->seekable = $meta['seekable'] && \fseek($new->stream, 0, SEEK_CUR) === 0;
127+
$meta = stream_get_meta_data($new->stream);
128+
$new->seekable = $meta['seekable'] && fseek($new->stream, 0, SEEK_CUR) === 0;
114129
$new->readable = isset(self::READ_WRITE_HASH['read'][$meta['mode']]);
115130
$new->writable = isset(self::READ_WRITE_HASH['write'][$meta['mode']]);
116131
$new->uri = $new->getMetadata('uri');
@@ -124,8 +139,8 @@ public static function create($body = ''): StreamInterface
124139
public function close(): void
125140
{
126141
if (isset($this->stream)) {
127-
if (\is_resource($this->stream)) {
128-
\fclose($this->stream);
142+
if (is_resource($this->stream)) {
143+
fclose($this->stream);
129144
}
130145
$this->detach();
131146
}
@@ -157,10 +172,10 @@ public function getSize(): ?int
157172

158173
// Clear the stat cache if the stream has a URI
159174
if ($this->uri) {
160-
\clearstatcache(true, $this->uri);
175+
clearstatcache(true, $this->uri);
161176
}
162177

163-
$stats = \fstat($this->stream);
178+
$stats = fstat($this->stream);
164179
if (isset($stats['size'])) {
165180
$this->size = $stats['size'];
166181

@@ -172,7 +187,7 @@ public function getSize(): ?int
172187

173188
public function tell(): int
174189
{
175-
if (false === $result = \ftell($this->stream)) {
190+
if (false === $result = ftell($this->stream)) {
176191
throw new RuntimeException('Unable to determine stream position');
177192
}
178193

@@ -181,7 +196,7 @@ public function tell(): int
181196

182197
public function eof(): bool
183198
{
184-
return ! $this->stream || \feof($this->stream);
199+
return ! $this->stream || feof($this->stream);
185200
}
186201

187202
public function isSeekable(): bool
@@ -195,8 +210,8 @@ public function seek($offset, $whence = SEEK_SET): void
195210
throw new RuntimeException('Stream is not seekable');
196211
}
197212

198-
if (\fseek($this->stream, $offset, $whence) === -1) {
199-
throw new RuntimeException('Unable to seek to stream position ' . $offset . ' with whence ' . \var_export($whence, true));
213+
if (fseek($this->stream, $offset, $whence) === -1) {
214+
throw new RuntimeException('Unable to seek to stream position ' . $offset . ' with whence ' . var_export($whence, true));
200215
}
201216
}
202217

@@ -219,7 +234,7 @@ public function write($string): int
219234
// We can't know the size after writing anything
220235
$this->size = null;
221236

222-
if (false === $result = \fwrite($this->stream, $string)) {
237+
if (false === $result = fwrite($this->stream, $string)) {
223238
throw new RuntimeException('Unable to write to stream');
224239
}
225240

@@ -237,7 +252,7 @@ public function read($length): string
237252
throw new RuntimeException('Cannot read from non-readable stream');
238253
}
239254

240-
return \fread($this->stream, $length);
255+
return fread($this->stream, $length);
241256
}
242257

243258
public function getContents(): string
@@ -246,7 +261,7 @@ public function getContents(): string
246261
throw new RuntimeException('Unable to read stream contents');
247262
}
248263

249-
if (false === $contents = \stream_get_contents($this->stream)) {
264+
if (false === $contents = stream_get_contents($this->stream)) {
250265
throw new RuntimeException('Unable to read stream contents');
251266
}
252267

@@ -259,7 +274,7 @@ public function getMetadata($key = null)
259274
return $key ? null : [];
260275
}
261276

262-
$meta = \stream_get_meta_data($this->stream);
277+
$meta = stream_get_meta_data($this->stream);
263278

264279
if ($key === null) {
265280
return $meta;

0 commit comments

Comments
 (0)