Skip to content

Commit 7cae3e6

Browse files
committed
Code: fixes types for psr/http-message 2.0
1 parent 0b6de9d commit 7cae3e6

File tree

10 files changed

+123
-123
lines changed

10 files changed

+123
-123
lines changed

src/Io/AbstractMessage.php

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

68-
public function getProtocolVersion()
68+
public function getProtocolVersion(): string
6969
{
7070
return $this->protocolVersion;
7171
}
7272

73-
public function withProtocolVersion($version)
73+
public function withProtocolVersion(string $version): static
7474
{
75-
if ((string) $version === $this->protocolVersion) {
75+
if ($version === $this->protocolVersion) {
7676
return $this;
7777
}
7878

7979
$message = clone $this;
80-
$message->protocolVersion = (string) $version;
80+
$message->protocolVersion = $version;
8181

8282
return $message;
8383
}
8484

85-
public function getHeaders()
85+
public function getHeaders(): array
8686
{
8787
return $this->headers;
8888
}
8989

90-
public function hasHeader($name)
90+
public function hasHeader(string $name): bool
9191
{
9292
return isset($this->headerNamesLowerCase[\strtolower($name)]);
9393
}
9494

95-
public function getHeader($name)
95+
public function getHeader(string $name): array
9696
{
9797
$lower = \strtolower($name);
98-
return isset($this->headerNamesLowerCase[$lower]) ? $this->headers[$this->headerNamesLowerCase[$lower]] : array();
98+
return isset($this->headerNamesLowerCase[$lower]) ? $this->headers[$this->headerNamesLowerCase[$lower]] : [];
9999
}
100100

101-
public function getHeaderLine($name)
101+
public function getHeaderLine(string $name): string
102102
{
103103
return \implode(', ', $this->getHeader($name));
104104
}
105105

106-
public function withHeader($name, $value)
106+
public function withHeader(string $name, $value): static
107107
{
108-
if ($value === array()) {
108+
if ($value === []) {
109109
return $this->withoutHeader($name);
110110
} elseif (\is_array($value)) {
111111
foreach ($value as &$one) {
112112
$one = (string) $one;
113113
}
114114
} else {
115-
$value = array((string) $value);
115+
$value = [(string) $value];
116116
}
117117

118118
$lower = \strtolower($name);
119-
if (isset($this->headerNamesLowerCase[$lower]) && $this->headerNamesLowerCase[$lower] === (string) $name && $this->headers[$this->headerNamesLowerCase[$lower]] === $value) {
119+
if (isset($this->headerNamesLowerCase[$lower]) && $this->headerNamesLowerCase[$lower] === $name && $this->headers[$this->headerNamesLowerCase[$lower]] === $value) {
120120
return $this;
121121
}
122122

@@ -131,16 +131,16 @@ public function withHeader($name, $value)
131131
return $message;
132132
}
133133

134-
public function withAddedHeader($name, $value)
134+
public function withAddedHeader(string $name, $value): static
135135
{
136-
if ($value === array()) {
136+
if ($value === []) {
137137
return $this;
138138
}
139139

140-
return $this->withHeader($name, \array_merge($this->getHeader($name), \is_array($value) ? $value : array($value)));
140+
return $this->withHeader($name, \array_merge($this->getHeader($name), \is_array($value) ? $value : [$value]));
141141
}
142142

143-
public function withoutHeader($name)
143+
public function withoutHeader(string $name): static
144144
{
145145
$lower = \strtolower($name);
146146
if (!isset($this->headerNamesLowerCase[$lower])) {
@@ -153,12 +153,12 @@ public function withoutHeader($name)
153153
return $message;
154154
}
155155

156-
public function getBody()
156+
public function getBody(): StreamInterface
157157
{
158158
return $this->body;
159159
}
160160

161-
public function withBody(StreamInterface $body)
161+
public function withBody(StreamInterface $body): static
162162
{
163163
if ($body === $this->body) {
164164
return $this;

src/Io/AbstractRequest.php

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

74-
public function getRequestTarget()
74+
public function getRequestTarget(): string
7575
{
7676
if ($this->requestTarget !== null) {
7777
return $this->requestTarget;
@@ -88,7 +88,7 @@ public function getRequestTarget()
8888
return $target;
8989
}
9090

91-
public function withRequestTarget($requestTarget)
91+
public function withRequestTarget(string $requestTarget): static
9292
{
9393
if ((string) $requestTarget === $this->requestTarget) {
9494
return $this;
@@ -100,12 +100,12 @@ public function withRequestTarget($requestTarget)
100100
return $request;
101101
}
102102

103-
public function getMethod()
103+
public function getMethod(): string
104104
{
105105
return $this->method;
106106
}
107107

108-
public function withMethod($method)
108+
public function withMethod(string $method): static
109109
{
110110
if ((string) $method === $this->method) {
111111
return $this;
@@ -117,12 +117,12 @@ public function withMethod($method)
117117
return $request;
118118
}
119119

120-
public function getUri()
120+
public function getUri(): UriInterface
121121
{
122122
return $this->uri;
123123
}
124124

125-
public function withUri(UriInterface $uri, $preserveHost = false)
125+
public function withUri(UriInterface $uri, bool $preserveHost = false): static
126126
{
127127
if ($uri === $this->uri) {
128128
return $this;

src/Io/BufferedBody.php

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

26-
public function __toString()
26+
public function __toString(): string
2727
{
2828
if ($this->closed) {
2929
return '';
@@ -34,26 +34,26 @@ public function __toString()
3434
return $this->getContents();
3535
}
3636

37-
public function close()
37+
public function close(): void
3838
{
3939
$this->buffer = '';
4040
$this->position = 0;
4141
$this->closed = true;
4242
}
4343

44-
public function detach()
44+
public function detach(): mixed
4545
{
4646
$this->close();
4747

4848
return null;
4949
}
5050

51-
public function getSize()
51+
public function getSize(): ?int
5252
{
5353
return $this->closed ? null : \strlen($this->buffer);
5454
}
5555

56-
public function tell()
56+
public function tell(): int
5757
{
5858
if ($this->closed) {
5959
throw new \RuntimeException('Unable to tell position of closed stream');
@@ -62,17 +62,17 @@ public function tell()
6262
return $this->position;
6363
}
6464

65-
public function eof()
65+
public function eof(): bool
6666
{
6767
return $this->position >= \strlen($this->buffer);
6868
}
6969

70-
public function isSeekable()
70+
public function isSeekable(): bool
7171
{
7272
return !$this->closed;
7373
}
7474

75-
public function seek($offset, $whence = \SEEK_SET)
75+
public function seek(int $offset, int $whence = \SEEK_SET): void
7676
{
7777
if ($this->closed) {
7878
throw new \RuntimeException('Unable to seek on closed stream');
@@ -96,17 +96,17 @@ public function seek($offset, $whence = \SEEK_SET)
9696
}
9797
}
9898

99-
public function rewind()
99+
public function rewind(): void
100100
{
101101
$this->seek(0);
102102
}
103103

104-
public function isWritable()
104+
public function isWritable(): bool
105105
{
106106
return !$this->closed;
107107
}
108108

109-
public function write($string)
109+
public function write(string $string): int
110110
{
111111
if ($this->closed) {
112112
throw new \RuntimeException('Unable to write to closed stream');
@@ -127,12 +127,12 @@ public function write($string)
127127
return $len;
128128
}
129129

130-
public function isReadable()
130+
public function isReadable(): bool
131131
{
132132
return !$this->closed;
133133
}
134134

135-
public function read($length)
135+
public function read(int $length): string
136136
{
137137
if ($this->closed) {
138138
throw new \RuntimeException('Unable to read from closed stream');
@@ -156,7 +156,7 @@ public function read($length)
156156
return \substr($this->buffer, $pos, $length);
157157
}
158158

159-
public function getContents()
159+
public function getContents(): string
160160
{
161161
if ($this->closed) {
162162
throw new \RuntimeException('Unable to read from closed stream');
@@ -172,7 +172,7 @@ public function getContents()
172172
return \substr($this->buffer, $pos);
173173
}
174174

175-
public function getMetadata($key = null)
175+
public function getMetadata(?string $key = null): mixed
176176
{
177177
return $key === null ? array() : null;
178178
}

src/Io/EmptyBodyStream.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class EmptyBodyStream extends EventEmitter implements StreamInterface, ReadableS
2929
{
3030
private $closed = false;
3131

32-
public function isReadable()
32+
public function isReadable(): bool
3333
{
3434
return !$this->closed;
3535
}
@@ -51,7 +51,7 @@ public function pipe(WritableStreamInterface $dest, array $options = array())
5151
return $dest;
5252
}
5353

54-
public function close()
54+
public function close(): void
5555
{
5656
if ($this->closed) {
5757
return;
@@ -63,79 +63,79 @@ public function close()
6363
$this->removeAllListeners();
6464
}
6565

66-
public function getSize()
66+
public function getSize(): ?int
6767
{
6868
return 0;
6969
}
7070

7171
/** @ignore */
72-
public function __toString()
72+
public function __toString(): string
7373
{
7474
return '';
7575
}
7676

7777
/** @ignore */
78-
public function detach()
78+
public function detach(): mixed
7979
{
8080
return null;
8181
}
8282

8383
/** @ignore */
84-
public function tell()
84+
public function tell(): int
8585
{
8686
throw new \BadMethodCallException();
8787
}
8888

8989
/** @ignore */
90-
public function eof()
90+
public function eof(): bool
9191
{
9292
throw new \BadMethodCallException();
9393
}
9494

9595
/** @ignore */
96-
public function isSeekable()
96+
public function isSeekable(): bool
9797
{
9898
return false;
9999
}
100100

101101
/** @ignore */
102-
public function seek($offset, $whence = SEEK_SET)
102+
public function seek(int $offset, int $whence = SEEK_SET): void
103103
{
104104
throw new \BadMethodCallException();
105105
}
106106

107107
/** @ignore */
108-
public function rewind()
108+
public function rewind(): void
109109
{
110110
throw new \BadMethodCallException();
111111
}
112112

113113
/** @ignore */
114-
public function isWritable()
114+
public function isWritable(): bool
115115
{
116116
return false;
117117
}
118118

119119
/** @ignore */
120-
public function write($string)
120+
public function write(string $string): int
121121
{
122122
throw new \BadMethodCallException();
123123
}
124124

125125
/** @ignore */
126-
public function read($length)
126+
public function read(int $length): string
127127
{
128128
throw new \BadMethodCallException();
129129
}
130130

131131
/** @ignore */
132-
public function getContents()
132+
public function getContents(): string
133133
{
134134
return '';
135135
}
136136

137137
/** @ignore */
138-
public function getMetadata($key = null)
138+
public function getMetadata(?string $key = null): mixed
139139
{
140140
return ($key === null) ? array() : null;
141141
}

0 commit comments

Comments
 (0)