Skip to content

Commit 591da43

Browse files
committed
make compatible with stream interface
1 parent 4a69954 commit 591da43

File tree

3 files changed

+14
-21
lines changed

3 files changed

+14
-21
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",

phpunit.xml.dist

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
<testsuites>
99
<testsuite name="Socket Client Test Suite">
1010
<directory>tests/</directory>
11-
<exclude>tests/SocketClientFeatureTest.php</exclude>
1211
</testsuite>
1312
</testsuites>
1413
<php>

src/Stream.php

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

64-
public function __toString()
64+
public function __toString(): string
6565
{
6666
try {
6767
return $this->getContents();
@@ -70,7 +70,7 @@ public function __toString()
7070
}
7171
}
7272

73-
public function close()
73+
public function close(): void
7474
{
7575
if ($this->isDetached || null === $this->socket) {
7676
throw new StreamException('Stream is detached');
@@ -93,12 +93,12 @@ public function detach()
9393
/**
9494
* @return int<0, max>|null
9595
*/
96-
public function getSize()
96+
public function getSize(): ?int
9797
{
9898
return $this->size;
9999
}
100100

101-
public function tell()
101+
public function tell(): int
102102
{
103103
if ($this->isDetached || null === $this->socket) {
104104
throw new StreamException('Stream is detached');
@@ -111,7 +111,7 @@ public function tell()
111111
return $tell;
112112
}
113113

114-
public function eof()
114+
public function eof(): bool
115115
{
116116
if ($this->isDetached || null === $this->socket) {
117117
throw new StreamException('Stream is detached');
@@ -120,46 +120,40 @@ public function eof()
120120
return feof($this->socket);
121121
}
122122

123-
public function isSeekable()
123+
public function isSeekable(): bool
124124
{
125125
return false;
126126
}
127127

128-
/**
129-
* @return void
130-
*/
131-
public function seek($offset, $whence = SEEK_SET)
128+
public function seek($offset, $whence = SEEK_SET): void
132129
{
133130
throw new StreamException('This stream is not seekable');
134131
}
135132

136-
/**
137-
* @return void
138-
*/
139-
public function rewind()
133+
public function rewind(): void
140134
{
141135
throw new StreamException('This stream is not seekable');
142136
}
143137

144-
public function isWritable()
138+
public function isWritable(): bool
145139
{
146140
return false;
147141
}
148142

149-
public function write($string)
143+
public function write($string): int
150144
{
151145
throw new StreamException('This stream is not writable');
152146
}
153147

154-
public function isReadable()
148+
public function isReadable(): bool
155149
{
156150
return true;
157151
}
158152

159153
/**
160154
* @param int<0, max> $length
161155
*/
162-
public function read($length)
156+
public function read($length): string
163157
{
164158
if ($this->isDetached || null === $this->socket) {
165159
throw new StreamException('Stream is detached');
@@ -197,7 +191,7 @@ public function read($length)
197191
return $read;
198192
}
199193

200-
public function getContents()
194+
public function getContents(): string
201195
{
202196
if ($this->isDetached || null === $this->socket) {
203197
throw new StreamException('Stream is detached');

0 commit comments

Comments
 (0)