Skip to content

Commit 3faec66

Browse files
committed
make compatible with stream interface
1 parent 84b0da5 commit 3faec66

File tree

2 files changed

+14
-57
lines changed

2 files changed

+14
-57
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
}
1010
],
1111
"require": {
12-
"php": "^7.2 || ^8.0",
12+
"php": "^7.4 || ^8.0",
1313
"nyholm/psr7": "^1.3",
1414
"php-http/httplug": "^2.0",
1515
"psr/http-client": "^1.0",

src/Stream.php

+13-56
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,7 @@ public function __construct(RequestInterface $request, $socket, ?int $size = nul
6161
$this->request = $request;
6262
}
6363

64-
/**
65-
* {@inheritdoc}
66-
*/
67-
public function __toString()
64+
public function __toString(): string
6865
{
6966
try {
7067
return $this->getContents();
@@ -73,20 +70,14 @@ public function __toString()
7370
}
7471
}
7572

76-
/**
77-
* {@inheritdoc}
78-
*/
79-
public function close()
73+
public function close(): void
8074
{
8175
if ($this->isDetached || null === $this->socket) {
8276
throw new StreamException('Stream is detached');
8377
}
8478
fclose($this->socket);
8579
}
8680

87-
/**
88-
* {@inheritdoc}
89-
*/
9081
public function detach()
9182
{
9283
if ($this->isDetached) {
@@ -104,15 +95,12 @@ public function detach()
10495
*
10596
* @return int<0, max>|null
10697
*/
107-
public function getSize()
98+
public function getSize(): ?int
10899
{
109100
return $this->size;
110101
}
111102

112-
/**
113-
* {@inheritdoc}
114-
*/
115-
public function tell()
103+
public function tell(): int
116104
{
117105
if ($this->isDetached || null === $this->socket) {
118106
throw new StreamException('Stream is detached');
@@ -125,10 +113,7 @@ public function tell()
125113
return $tell;
126114
}
127115

128-
/**
129-
* {@inheritdoc}
130-
*/
131-
public function eof()
116+
public function eof(): bool
132117
{
133118
if ($this->isDetached || null === $this->socket) {
134119
throw new StreamException('Stream is detached');
@@ -137,54 +122,32 @@ public function eof()
137122
return feof($this->socket);
138123
}
139124

140-
/**
141-
* {@inheritdoc}
142-
*/
143-
public function isSeekable()
125+
public function isSeekable(): bool
144126
{
145127
return false;
146128
}
147129

148-
/**
149-
* {@inheritdoc}
150-
*
151-
* @return void
152-
*/
153-
public function seek($offset, $whence = SEEK_SET)
130+
public function seek($offset, $whence = SEEK_SET): void
154131
{
155132
throw new StreamException('This stream is not seekable');
156133
}
157134

158-
/**
159-
* {@inheritdoc}
160-
*
161-
* @return void
162-
*/
163-
public function rewind()
135+
public function rewind(): void
164136
{
165137
throw new StreamException('This stream is not seekable');
166138
}
167139

168-
/**
169-
* {@inheritdoc}
170-
*/
171-
public function isWritable()
140+
public function isWritable(): bool
172141
{
173142
return false;
174143
}
175144

176-
/**
177-
* {@inheritdoc}
178-
*/
179-
public function write($string)
145+
public function write($string): int
180146
{
181147
throw new StreamException('This stream is not writable');
182148
}
183149

184-
/**
185-
* {@inheritdoc}
186-
*/
187-
public function isReadable()
150+
public function isReadable(): bool
188151
{
189152
return true;
190153
}
@@ -194,7 +157,7 @@ public function isReadable()
194157
*
195158
* @param int<0, max> $length
196159
*/
197-
public function read($length)
160+
public function read($length): string
198161
{
199162
if ($this->isDetached || null === $this->socket) {
200163
throw new StreamException('Stream is detached');
@@ -232,10 +195,7 @@ public function read($length)
232195
return $read;
233196
}
234197

235-
/**
236-
* {@inheritdoc}
237-
*/
238-
public function getContents()
198+
public function getContents(): string
239199
{
240200
if ($this->isDetached || null === $this->socket) {
241201
throw new StreamException('Stream is detached');
@@ -261,9 +221,6 @@ public function getContents()
261221
return $contents;
262222
}
263223

264-
/**
265-
* {@inheritdoc}
266-
*/
267224
public function getMetadata($key = null)
268225
{
269226
if ($this->isDetached || null === $this->socket) {

0 commit comments

Comments
 (0)