Skip to content

Commit 7e32b4c

Browse files
author
Jonathon Hill
committed
Fix type compatibility with psr/http-message v2.x
1 parent c0a32c1 commit 7e32b4c

10 files changed

Lines changed: 392 additions & 113 deletions

src/Io/AbstractMessage.php

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,18 @@ protected function __construct($protocolVersion, array $headers, StreamInterface
6565
$this->body = $body;
6666
}
6767

68-
public function getProtocolVersion()
68+
/**
69+
* @inheritdoc
70+
*/
71+
public function getProtocolVersion(): string
6972
{
7073
return $this->protocolVersion;
7174
}
7275

73-
public function withProtocolVersion($version)
76+
/**
77+
* @inheritdoc
78+
*/
79+
public function withProtocolVersion(string $version): MessageInterface
7480
{
7581
if ((string) $version === $this->protocolVersion) {
7682
return $this;
@@ -82,28 +88,43 @@ public function withProtocolVersion($version)
8288
return $message;
8389
}
8490

85-
public function getHeaders()
91+
/**
92+
* @inheritdoc
93+
*/
94+
public function getHeaders(): array
8695
{
8796
return $this->headers;
8897
}
8998

90-
public function hasHeader($name)
99+
/**
100+
* @inheritdoc
101+
*/
102+
public function hasHeader(string $name): bool
91103
{
92104
return isset($this->headerNamesLowerCase[\strtolower($name)]);
93105
}
94106

95-
public function getHeader($name)
107+
/**
108+
* @inheritdoc
109+
*/
110+
public function getHeader(string $name): array
96111
{
97112
$lower = \strtolower($name);
98113
return isset($this->headerNamesLowerCase[$lower]) ? $this->headers[$this->headerNamesLowerCase[$lower]] : array();
99114
}
100115

101-
public function getHeaderLine($name)
116+
/**
117+
* @inheritdoc
118+
*/
119+
public function getHeaderLine(string $name): string
102120
{
103121
return \implode(', ', $this->getHeader($name));
104122
}
105123

106-
public function withHeader($name, $value)
124+
/**
125+
* @inheritdoc
126+
*/
127+
public function withHeader(string $name, $value): MessageInterface
107128
{
108129
if ($value === array()) {
109130
return $this->withoutHeader($name);
@@ -131,7 +152,10 @@ public function withHeader($name, $value)
131152
return $message;
132153
}
133154

134-
public function withAddedHeader($name, $value)
155+
/**
156+
* @inheritdoc
157+
*/
158+
public function withAddedHeader(string $name, $value): MessageInterface
135159
{
136160
if ($value === array()) {
137161
return $this;
@@ -140,7 +164,10 @@ public function withAddedHeader($name, $value)
140164
return $this->withHeader($name, \array_merge($this->getHeader($name), \is_array($value) ? $value : array($value)));
141165
}
142166

143-
public function withoutHeader($name)
167+
/**
168+
* @inheritdoc
169+
*/
170+
public function withoutHeader(string $name): MessageInterface
144171
{
145172
$lower = \strtolower($name);
146173
if (!isset($this->headerNamesLowerCase[$lower])) {
@@ -153,12 +180,18 @@ public function withoutHeader($name)
153180
return $message;
154181
}
155182

156-
public function getBody()
183+
/**
184+
* @inheritdoc
185+
*/
186+
public function getBody(): StreamInterface
157187
{
158188
return $this->body;
159189
}
160190

161-
public function withBody(StreamInterface $body)
191+
/**
192+
* @inheritdoc
193+
*/
194+
public function withBody(StreamInterface $body): MessageInterface
162195
{
163196
if ($body === $this->body) {
164197
return $this;

src/Io/AbstractRequest.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ protected function __construct(
7171
$this->uri = $uri;
7272
}
7373

74-
public function getRequestTarget()
74+
/**
75+
* @inheritdoc
76+
*/
77+
public function getRequestTarget(): string
7578
{
7679
if ($this->requestTarget !== null) {
7780
return $this->requestTarget;
@@ -88,7 +91,10 @@ public function getRequestTarget()
8891
return $target;
8992
}
9093

91-
public function withRequestTarget($requestTarget)
94+
/**
95+
* @inheritdoc
96+
*/
97+
public function withRequestTarget(string $requestTarget): RequestInterface
9298
{
9399
if ((string) $requestTarget === $this->requestTarget) {
94100
return $this;
@@ -100,12 +106,18 @@ public function withRequestTarget($requestTarget)
100106
return $request;
101107
}
102108

103-
public function getMethod()
109+
/**
110+
* @inheritdoc
111+
*/
112+
public function getMethod(): string
104113
{
105114
return $this->method;
106115
}
107116

108-
public function withMethod($method)
117+
/**
118+
* @inheritdoc
119+
*/
120+
public function withMethod(string $method): RequestInterface
109121
{
110122
if ((string) $method === $this->method) {
111123
return $this;
@@ -117,12 +129,18 @@ public function withMethod($method)
117129
return $request;
118130
}
119131

120-
public function getUri()
132+
/**
133+
* @inheritdoc
134+
*/
135+
public function getUri(): UriInterface
121136
{
122137
return $this->uri;
123138
}
124139

125-
public function withUri(UriInterface $uri, $preserveHost = false)
140+
/**
141+
* @inheritdoc
142+
*/
143+
public function withUri(UriInterface $uri, bool $preserveHost = false): RequestInterface
126144
{
127145
if ($uri === $this->uri) {
128146
return $this;

src/Io/BufferedBody.php

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ public function __construct($buffer)
2323
$this->buffer = $buffer;
2424
}
2525

26-
public function __toString()
26+
/**
27+
* @inheritdoc
28+
*/
29+
public function __toString(): string
2730
{
2831
if ($this->closed) {
2932
return '';
@@ -34,26 +37,38 @@ public function __toString()
3437
return $this->getContents();
3538
}
3639

37-
public function close()
40+
/**
41+
* @inheritdoc
42+
*/
43+
public function close(): void
3844
{
3945
$this->buffer = '';
4046
$this->position = 0;
4147
$this->closed = true;
4248
}
4349

50+
/**
51+
* @inheritdoc
52+
*/
4453
public function detach()
4554
{
4655
$this->close();
4756

4857
return null;
4958
}
5059

51-
public function getSize()
60+
/**
61+
* @inheritdoc
62+
*/
63+
public function getSize(): ?int
5264
{
5365
return $this->closed ? null : \strlen($this->buffer);
5466
}
5567

56-
public function tell()
68+
/**
69+
* @inheritdoc
70+
*/
71+
public function tell(): int
5772
{
5873
if ($this->closed) {
5974
throw new \RuntimeException('Unable to tell position of closed stream');
@@ -62,17 +77,26 @@ public function tell()
6277
return $this->position;
6378
}
6479

65-
public function eof()
80+
/**
81+
* @inheritdoc
82+
*/
83+
public function eof(): bool
6684
{
6785
return $this->position >= \strlen($this->buffer);
6886
}
6987

70-
public function isSeekable()
88+
/**
89+
* @inheritdoc
90+
*/
91+
public function isSeekable(): bool
7192
{
7293
return !$this->closed;
7394
}
7495

75-
public function seek($offset, $whence = \SEEK_SET)
96+
/**
97+
* @inheritdoc
98+
*/
99+
public function seek($offset, $whence = \SEEK_SET): void
76100
{
77101
if ($this->closed) {
78102
throw new \RuntimeException('Unable to seek on closed stream');
@@ -96,17 +120,26 @@ public function seek($offset, $whence = \SEEK_SET)
96120
}
97121
}
98122

99-
public function rewind()
123+
/**
124+
* @inheritdoc
125+
*/
126+
public function rewind(): void
100127
{
101128
$this->seek(0);
102129
}
103130

104-
public function isWritable()
131+
/**
132+
* @inheritdoc
133+
*/
134+
public function isWritable(): bool
105135
{
106136
return !$this->closed;
107137
}
108138

109-
public function write($string)
139+
/**
140+
* @inheritdoc
141+
*/
142+
public function write(string $string): int
110143
{
111144
if ($this->closed) {
112145
throw new \RuntimeException('Unable to write to closed stream');
@@ -127,12 +160,18 @@ public function write($string)
127160
return $len;
128161
}
129162

130-
public function isReadable()
163+
/**
164+
* @inheritdoc
165+
*/
166+
public function isReadable(): bool
131167
{
132168
return !$this->closed;
133169
}
134170

135-
public function read($length)
171+
/**
172+
* @inheritdoc
173+
*/
174+
public function read(int $length): string
136175
{
137176
if ($this->closed) {
138177
throw new \RuntimeException('Unable to read from closed stream');
@@ -156,7 +195,10 @@ public function read($length)
156195
return \substr($this->buffer, $pos, $length);
157196
}
158197

159-
public function getContents()
198+
/**
199+
* @inheritdoc
200+
*/
201+
public function getContents(): string
160202
{
161203
if ($this->closed) {
162204
throw new \RuntimeException('Unable to read from closed stream');
@@ -172,7 +214,10 @@ public function getContents()
172214
return \substr($this->buffer, $pos);
173215
}
174216

175-
public function getMetadata($key = null)
217+
/**
218+
* @inheritdoc
219+
*/
220+
public function getMetadata($key = null): ?array
176221
{
177222
return $key === null ? array() : null;
178223
}

0 commit comments

Comments
 (0)