diff --git a/composer.json b/composer.json index 4234210a..b7db5b84 100644 --- a/composer.json +++ b/composer.json @@ -29,17 +29,15 @@ "php": ">=5.3.0", "evenement/evenement": "^3.0 || ^2.0 || ^1.0", "fig/http-message-util": "^1.1", - "psr/http-message": "^1.0", + "psr/http-message": "^1.0 || ^2.0", "react/event-loop": "^1.2", "react/promise": "^3.2 || ^2.3 || ^1.2.1", "react/socket": "^1.16", "react/stream": "^1.4" }, "require-dev": { - "clue/http-proxy-react": "^1.8", - "clue/reactphp-ssh-proxy": "^1.4", - "clue/socks-react": "^1.4", "phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36", + "psr/http-message": "^1.0 || ^2.0", "react/async": "^4.2 || ^3 || ^2", "react/promise-stream": "^1.4", "react/promise-timer": "^1.11" diff --git a/src/Io/AbstractMessage.php b/src/Io/AbstractMessage.php index a0706bb1..2356b419 100644 --- a/src/Io/AbstractMessage.php +++ b/src/Io/AbstractMessage.php @@ -65,12 +65,19 @@ protected function __construct($protocolVersion, array $headers, StreamInterface $this->body = $body; } - public function getProtocolVersion() + /** + * @inheritdoc + */ + public function getProtocolVersion(): string { return $this->protocolVersion; } - public function withProtocolVersion($version) + /** + * @inheritdoc + * @param string $version + */ + public function withProtocolVersion($version): self { if ((string) $version === $this->protocolVersion) { return $this; @@ -82,28 +89,47 @@ public function withProtocolVersion($version) return $message; } - public function getHeaders() + /** + * @inheritdoc + */ + public function getHeaders(): array { return $this->headers; } - public function hasHeader($name) + /** + * @inheritdoc + * @param string $name + */ + public function hasHeader($name): bool { return isset($this->headerNamesLowerCase[\strtolower($name)]); } - public function getHeader($name) + /** + * @inheritdoc + * @param string $name + */ + public function getHeader($name): array { $lower = \strtolower($name); return isset($this->headerNamesLowerCase[$lower]) ? $this->headers[$this->headerNamesLowerCase[$lower]] : array(); } - public function getHeaderLine($name) + /** + * @inheritdoc + * @param string $name + */ + public function getHeaderLine($name): string { return \implode(', ', $this->getHeader($name)); } - public function withHeader($name, $value) + /** + * @inheritdoc + * @param string $name + */ + public function withHeader($name, $value): self { if ($value === array()) { return $this->withoutHeader($name); @@ -131,7 +157,11 @@ public function withHeader($name, $value) return $message; } - public function withAddedHeader($name, $value) + /** + * @inheritdoc + * @param string $name + */ + public function withAddedHeader($name, $value): self { if ($value === array()) { return $this; @@ -140,7 +170,11 @@ public function withAddedHeader($name, $value) return $this->withHeader($name, \array_merge($this->getHeader($name), \is_array($value) ? $value : array($value))); } - public function withoutHeader($name) + /** + * @inheritdoc + * @param string $name + */ + public function withoutHeader($name): self { $lower = \strtolower($name); if (!isset($this->headerNamesLowerCase[$lower])) { @@ -153,12 +187,18 @@ public function withoutHeader($name) return $message; } - public function getBody() + /** + * @inheritdoc + */ + public function getBody(): StreamInterface { return $this->body; } - public function withBody(StreamInterface $body) + /** + * @inheritdoc + */ + public function withBody(StreamInterface $body): self { if ($body === $this->body) { return $this; diff --git a/src/Io/AbstractRequest.php b/src/Io/AbstractRequest.php index f32307f7..32c37042 100644 --- a/src/Io/AbstractRequest.php +++ b/src/Io/AbstractRequest.php @@ -71,7 +71,10 @@ protected function __construct( $this->uri = $uri; } - public function getRequestTarget() + /** + * @inheritdoc + */ + public function getRequestTarget(): string { if ($this->requestTarget !== null) { return $this->requestTarget; @@ -88,7 +91,10 @@ public function getRequestTarget() return $target; } - public function withRequestTarget($requestTarget) + /** + * @inheritdoc + */ + public function withRequestTarget(string $requestTarget): RequestInterface { if ((string) $requestTarget === $this->requestTarget) { return $this; @@ -100,12 +106,18 @@ public function withRequestTarget($requestTarget) return $request; } - public function getMethod() + /** + * @inheritdoc + */ + public function getMethod(): string { return $this->method; } - public function withMethod($method) + /** + * @inheritdoc + */ + public function withMethod(string $method): RequestInterface { if ((string) $method === $this->method) { return $this; @@ -117,12 +129,18 @@ public function withMethod($method) return $request; } - public function getUri() + /** + * @inheritdoc + */ + public function getUri(): UriInterface { return $this->uri; } - public function withUri(UriInterface $uri, $preserveHost = false) + /** + * @inheritdoc + */ + public function withUri(UriInterface $uri, bool $preserveHost = false): RequestInterface { if ($uri === $this->uri) { return $this; diff --git a/src/Io/BufferedBody.php b/src/Io/BufferedBody.php index 4a4d8393..0a700706 100644 --- a/src/Io/BufferedBody.php +++ b/src/Io/BufferedBody.php @@ -23,7 +23,10 @@ public function __construct($buffer) $this->buffer = $buffer; } - public function __toString() + /** + * @inheritdoc + */ + public function __toString(): string { if ($this->closed) { return ''; @@ -34,13 +37,19 @@ public function __toString() return $this->getContents(); } - public function close() + /** + * @inheritdoc + */ + public function close(): void { $this->buffer = ''; $this->position = 0; $this->closed = true; } + /** + * @inheritdoc + */ public function detach() { $this->close(); @@ -48,12 +57,18 @@ public function detach() return null; } - public function getSize() + /** + * @inheritdoc + */ + public function getSize(): ?int { return $this->closed ? null : \strlen($this->buffer); } - public function tell() + /** + * @inheritdoc + */ + public function tell(): int { if ($this->closed) { throw new \RuntimeException('Unable to tell position of closed stream'); @@ -62,17 +77,26 @@ public function tell() return $this->position; } - public function eof() + /** + * @inheritdoc + */ + public function eof(): bool { return $this->position >= \strlen($this->buffer); } - public function isSeekable() + /** + * @inheritdoc + */ + public function isSeekable(): bool { return !$this->closed; } - public function seek($offset, $whence = \SEEK_SET) + /** + * @inheritdoc + */ + public function seek($offset, $whence = \SEEK_SET): void { if ($this->closed) { throw new \RuntimeException('Unable to seek on closed stream'); @@ -96,17 +120,26 @@ public function seek($offset, $whence = \SEEK_SET) } } - public function rewind() + /** + * @inheritdoc + */ + public function rewind(): void { $this->seek(0); } - public function isWritable() + /** + * @inheritdoc + */ + public function isWritable(): bool { return !$this->closed; } - public function write($string) + /** + * @inheritdoc + */ + public function write(string $string): int { if ($this->closed) { throw new \RuntimeException('Unable to write to closed stream'); @@ -127,12 +160,18 @@ public function write($string) return $len; } - public function isReadable() + /** + * @inheritdoc + */ + public function isReadable(): bool { return !$this->closed; } - public function read($length) + /** + * @inheritdoc + */ + public function read(int $length): string { if ($this->closed) { throw new \RuntimeException('Unable to read from closed stream'); @@ -156,7 +195,10 @@ public function read($length) return \substr($this->buffer, $pos, $length); } - public function getContents() + /** + * @inheritdoc + */ + public function getContents(): string { if ($this->closed) { throw new \RuntimeException('Unable to read from closed stream'); @@ -172,7 +214,10 @@ public function getContents() return \substr($this->buffer, $pos); } - public function getMetadata($key = null) + /** + * @inheritdoc + */ + public function getMetadata($key = null): ?array { return $key === null ? array() : null; } diff --git a/src/Io/EmptyBodyStream.php b/src/Io/EmptyBodyStream.php index 5056219c..848e7965 100644 --- a/src/Io/EmptyBodyStream.php +++ b/src/Io/EmptyBodyStream.php @@ -29,21 +29,33 @@ class EmptyBodyStream extends EventEmitter implements StreamInterface, ReadableS { private $closed = false; - public function isReadable() + /** + * @inheritdoc + */ + public function isReadable(): bool { return !$this->closed; } - public function pause() + /** + * @inheritdoc + */ + public function pause(): void { // NOOP } - public function resume() + /** + * @inheritdoc + */ + public function resume(): void { // NOOP } + /** + * @inheritdoc + */ public function pipe(WritableStreamInterface $dest, array $options = array()) { Util::pipe($this, $dest, $options); @@ -51,7 +63,10 @@ public function pipe(WritableStreamInterface $dest, array $options = array()) return $dest; } - public function close() + /** + * @inheritdoc + */ + public function close(): void { if ($this->closed) { return; @@ -63,13 +78,16 @@ public function close() $this->removeAllListeners(); } - public function getSize() + /** + * @inheritdoc + */ + public function getSize(): ?int { return 0; } /** @ignore */ - public function __toString() + public function __toString(): string { return ''; } @@ -81,55 +99,55 @@ public function detach() } /** @ignore */ - public function tell() + public function tell(): int { throw new \BadMethodCallException(); } /** @ignore */ - public function eof() + public function eof(): bool { throw new \BadMethodCallException(); } /** @ignore */ - public function isSeekable() + public function isSeekable(): bool { return false; } /** @ignore */ - public function seek($offset, $whence = SEEK_SET) + public function seek($offset, $whence = SEEK_SET): void { throw new \BadMethodCallException(); } /** @ignore */ - public function rewind() + public function rewind(): void { throw new \BadMethodCallException(); } /** @ignore */ - public function isWritable() + public function isWritable(): bool { return false; } /** @ignore */ - public function write($string) + public function write($string): int { throw new \BadMethodCallException(); } /** @ignore */ - public function read($length) + public function read(int $length): string { throw new \BadMethodCallException(); } /** @ignore */ - public function getContents() + public function getContents(): string { return ''; } diff --git a/src/Io/HttpBodyStream.php b/src/Io/HttpBodyStream.php index 25d15a18..56da2d61 100644 --- a/src/Io/HttpBodyStream.php +++ b/src/Io/HttpBodyStream.php @@ -45,21 +45,33 @@ public function __construct(ReadableStreamInterface $input, $size) $this->input->on('close', array($this, 'close')); } - public function isReadable() + /** + * @inheritdoc + */ + public function isReadable(): bool { return !$this->closed && $this->input->isReadable(); } - public function pause() + /** + * @inheritdoc + */ + public function pause(): void { $this->input->pause(); } - public function resume() + /** + * @inheritdoc + */ + public function resume(): void { $this->input->resume(); } + /** + * @inheritdoc + */ public function pipe(WritableStreamInterface $dest, array $options = array()) { Util::pipe($this, $dest, $options); @@ -67,7 +79,10 @@ public function pipe(WritableStreamInterface $dest, array $options = array()) return $dest; } - public function close() + /** + * @inheritdoc + */ + public function close(): void { if ($this->closed) { return; @@ -81,13 +96,16 @@ public function close() $this->removeAllListeners(); } - public function getSize() + /** + * @inheritdoc + */ + public function getSize(): ?int { return $this->size; } /** @ignore */ - public function __toString() + public function __toString(): string { return ''; } @@ -99,55 +117,55 @@ public function detach() } /** @ignore */ - public function tell() + public function tell(): int { throw new \BadMethodCallException(); } /** @ignore */ - public function eof() + public function eof(): bool { throw new \BadMethodCallException(); } /** @ignore */ - public function isSeekable() + public function isSeekable(): bool { return false; } /** @ignore */ - public function seek($offset, $whence = SEEK_SET) + public function seek(int $offset, int $whence = SEEK_SET): void { throw new \BadMethodCallException(); } /** @ignore */ - public function rewind() + public function rewind(): void { throw new \BadMethodCallException(); } /** @ignore */ - public function isWritable() + public function isWritable(): bool { return false; } /** @ignore */ - public function write($string) + public function write(string $string): int { throw new \BadMethodCallException(); } /** @ignore */ - public function read($length) + public function read(int $length): string { throw new \BadMethodCallException(); } /** @ignore */ - public function getContents() + public function getContents(): string { return ''; } diff --git a/src/Io/ReadableBodyStream.php b/src/Io/ReadableBodyStream.php index daef45f9..7b8e255e 100644 --- a/src/Io/ReadableBodyStream.php +++ b/src/Io/ReadableBodyStream.php @@ -41,7 +41,10 @@ public function __construct(ReadableStreamInterface $input, $size = null) $input->on('close', array($that, 'close')); } - public function close() + /** + * @inheritdoc + */ + public function close(): void { if (!$this->closed) { $this->closed = true; @@ -52,21 +55,33 @@ public function close() } } - public function isReadable() + /** + * @inheritdoc + */ + public function isReadable(): bool { return $this->input->isReadable(); } - public function pause() + /** + * @inheritdoc + */ + public function pause(): void { $this->input->pause(); } - public function resume() + /** + * @inheritdoc + */ + public function resume(): void { $this->input->resume(); } + /** + * @inheritdoc + */ public function pipe(WritableStreamInterface $dest, array $options = array()) { Util::pipe($this, $dest, $options); @@ -74,12 +89,18 @@ public function pipe(WritableStreamInterface $dest, array $options = array()) return $dest; } - public function eof() + /** + * @inheritdoc + */ + public function eof(): bool { return !$this->isReadable(); } - public function __toString() + /** + * @inheritdoc + */ + public function __toString(): string { return ''; } @@ -89,52 +110,82 @@ public function detach() throw new \BadMethodCallException(); } - public function getSize() + /** + * @inheritdoc + */ + public function getSize(): ?int { return $this->size; } - public function tell() + /** + * @inheritdoc + */ + public function tell(): int { throw new \BadMethodCallException(); } - public function isSeekable() + /** + * @inheritdoc + */ + public function isSeekable(): bool { return false; } - public function seek($offset, $whence = SEEK_SET) + /** + * @inheritdoc + */ + public function seek(int $offset, int $whence = SEEK_SET): void { throw new \BadMethodCallException(); } - public function rewind() + /** + * @inheritdoc + */ + public function rewind(): void { throw new \BadMethodCallException(); } - public function isWritable() + /** + * @inheritdoc + */ + public function isWritable(): bool { return false; } - public function write($string) + /** + * @inheritdoc + */ + public function write(string $string): int { throw new \BadMethodCallException(); } - public function read($length) + /** + * @inheritdoc + */ + public function read(int $length): string { throw new \BadMethodCallException(); } - public function getContents() + /** + * @inheritdoc + */ + public function getContents(): string { throw new \BadMethodCallException(); } - public function getMetadata($key = null) + /** + * @inheritdoc + */ + public function getMetadata(?string $key = null) { return ($key === null) ? array() : null; } diff --git a/src/Io/UploadedFile.php b/src/Io/UploadedFile.php index f2a6c9e7..841aebbd 100644 --- a/src/Io/UploadedFile.php +++ b/src/Io/UploadedFile.php @@ -79,7 +79,7 @@ public function __construct(StreamInterface $stream, $size, $error, $filename, $ /** * {@inheritdoc} */ - public function getStream() + public function getStream(): StreamInterface { if ($this->error !== \UPLOAD_ERR_OK) { throw new RuntimeException('Cannot retrieve stream due to upload error'); @@ -91,7 +91,7 @@ public function getStream() /** * {@inheritdoc} */ - public function moveTo($targetPath) + public function moveTo(string $targetPath): void { throw new RuntimeException('Not implemented'); } @@ -99,7 +99,7 @@ public function moveTo($targetPath) /** * {@inheritdoc} */ - public function getSize() + public function getSize(): ?int { return $this->size; } @@ -107,7 +107,7 @@ public function getSize() /** * {@inheritdoc} */ - public function getError() + public function getError(): int { return $this->error; } @@ -115,7 +115,7 @@ public function getError() /** * {@inheritdoc} */ - public function getClientFilename() + public function getClientFilename(): ?string { return $this->filename; } @@ -123,7 +123,7 @@ public function getClientFilename() /** * {@inheritdoc} */ - public function getClientMediaType() + public function getClientMediaType(): ?string { return $this->mediaType; } diff --git a/src/Message/Response.php b/src/Message/Response.php index fa6366ed..c3e3c37f 100644 --- a/src/Message/Response.php +++ b/src/Message/Response.php @@ -321,12 +321,18 @@ public function __construct( $this->reasonPhrase = ($reason !== '' && $reason !== null) ? (string) $reason : self::getReasonPhraseForStatusCode($status); } - public function getStatusCode() + /** + * @inheritdoc + */ + public function getStatusCode(): int { return $this->statusCode; } - public function withStatus($code, $reasonPhrase = '') + /** + * @inheritdoc + */ + public function withStatus(int $code, string $reasonPhrase = ''): self { if ((string) $reasonPhrase === '') { $reasonPhrase = self::getReasonPhraseForStatusCode($code); @@ -343,7 +349,10 @@ public function withStatus($code, $reasonPhrase = '') return $response; } - public function getReasonPhrase() + /** + * @inheritdoc + */ + public function getReasonPhrase(): string { return $this->reasonPhrase; } diff --git a/src/Message/ServerRequest.php b/src/Message/ServerRequest.php index 32a0f62f..d2769b06 100644 --- a/src/Message/ServerRequest.php +++ b/src/Message/ServerRequest.php @@ -87,65 +87,98 @@ public function __construct( } } - public function getServerParams() + /** + * @inheritdoc + */ + public function getServerParams(): array { return $this->serverParams; } - public function getCookieParams() + /** + * @inheritdoc + */ + public function getCookieParams(): array { return $this->cookies; } - public function withCookieParams(array $cookies) + /** + * @inheritdoc + */ + public function withCookieParams(array $cookies): self { $new = clone $this; $new->cookies = $cookies; return $new; } - public function getQueryParams() + /** + * @inheritdoc + */ + public function getQueryParams(): array { return $this->queryParams; } - public function withQueryParams(array $query) + /** + * @inheritdoc + */ + public function withQueryParams(array $query): self { $new = clone $this; $new->queryParams = $query; return $new; } - public function getUploadedFiles() + /** + * @inheritdoc + */ + public function getUploadedFiles(): array { return $this->fileParams; } - public function withUploadedFiles(array $uploadedFiles) + /** + * @inheritdoc + */ + public function withUploadedFiles(array $uploadedFiles): self { $new = clone $this; $new->fileParams = $uploadedFiles; return $new; } + /** + * @inheritdoc + */ public function getParsedBody() { return $this->parsedBody; } - public function withParsedBody($data) + /** + * @inheritdoc + */ + public function withParsedBody($data): self { $new = clone $this; $new->parsedBody = $data; return $new; } - public function getAttributes() + /** + * @inheritdoc + */ + public function getAttributes(): array { return $this->attributes; } - public function getAttribute($name, $default = null) + /** + * @inheritdoc + */ + public function getAttribute(string $name, $default = null) { if (!\array_key_exists($name, $this->attributes)) { return $default; @@ -153,14 +186,20 @@ public function getAttribute($name, $default = null) return $this->attributes[$name]; } - public function withAttribute($name, $value) + /** + * @inheritdoc + */ + public function withAttribute(string $name, $value): self { $new = clone $this; $new->attributes[$name] = $value; return $new; } - public function withoutAttribute($name) + /** + * @inheritdoc + */ + public function withoutAttribute(string $name): self { $new = clone $this; unset($new->attributes[$name]); diff --git a/src/Message/Uri.php b/src/Message/Uri.php index 1eaf24fe..82dce60a 100644 --- a/src/Message/Uri.php +++ b/src/Message/Uri.php @@ -88,12 +88,18 @@ public function __construct($uri) } } - public function getScheme() + /** + * @inheritdoc + */ + public function getScheme(): string { return $this->scheme; } - public function getAuthority() + /** + * @inheritdoc + */ + public function getAuthority(): string { if ($this->host === '') { return ''; @@ -102,37 +108,58 @@ public function getAuthority() return ($this->userInfo !== '' ? $this->userInfo . '@' : '') . $this->host . ($this->port !== null ? ':' . $this->port : ''); } - public function getUserInfo() + /** + * @inheritdoc + */ + public function getUserInfo(): string { return $this->userInfo; } - public function getHost() + /** + * @inheritdoc + */ + public function getHost(): string { return $this->host; } - public function getPort() + /** + * @inheritdoc + */ + public function getPort(): ?int { return $this->port; } - public function getPath() + /** + * @inheritdoc + */ + public function getPath(): string { return $this->path; } - public function getQuery() + /** + * @inheritdoc + */ + public function getQuery(): string { return $this->query; } - public function getFragment() + /** + * @inheritdoc + */ + public function getFragment(): string { return $this->fragment; } - public function withScheme($scheme) + /** + * @inheritdoc + */ + public function withScheme(string $scheme): self { $scheme = \strtolower($scheme); if ($scheme === $this->scheme) { @@ -153,7 +180,10 @@ public function withScheme($scheme) return $new; } - public function withUserInfo($user, $password = null) + /** + * @inheritdoc + */ + public function withUserInfo(string $user, ?string $password = null): self { $userInfo = $this->encode($user, \PHP_URL_USER) . ($password !== null ? ':' . $this->encode($password, \PHP_URL_PASS) : ''); if ($userInfo === $this->userInfo) { @@ -166,7 +196,10 @@ public function withUserInfo($user, $password = null) return $new; } - public function withHost($host) + /** + * @inheritdoc + */ + public function withHost(string $host): self { $host = \strtolower($host); if ($host === $this->host) { @@ -183,7 +216,10 @@ public function withHost($host) return $new; } - public function withPort($port) + /** + * @inheritdoc + */ + public function withPort(?int $port): self { $port = $port === null ? null : (int) $port; if (($port === 80 && $this->scheme === 'http') || ($port === 443 && $this->scheme === 'https')) { @@ -204,7 +240,10 @@ public function withPort($port) return $new; } - public function withPath($path) + /** + * @inheritdoc + */ + public function withPath(string $path): self { $path = $this->encode($path, \PHP_URL_PATH); if ($path === $this->path) { @@ -217,7 +256,10 @@ public function withPath($path) return $new; } - public function withQuery($query) + /** + * @inheritdoc + */ + public function withQuery(string $query): self { $query = $this->encode($query, \PHP_URL_QUERY); if ($query === $this->query) { @@ -230,7 +272,10 @@ public function withQuery($query) return $new; } - public function withFragment($fragment) + /** + * @inheritdoc + */ + public function withFragment(string $fragment): self { $fragment = $this->encode($fragment, \PHP_URL_FRAGMENT); if ($fragment === $this->fragment) { @@ -243,7 +288,10 @@ public function withFragment($fragment) return $new; } - public function __toString() + /** + * @inheritdoc + */ + public function __toString(): string { $uri = ''; if ($this->scheme !== '') { diff --git a/tests/Io/HttpBodyStreamTest.php b/tests/Io/HttpBodyStreamTest.php index db21dcf8..fa8e9b34 100644 --- a/tests/Io/HttpBodyStreamTest.php +++ b/tests/Io/HttpBodyStreamTest.php @@ -131,7 +131,7 @@ public function testWrite() public function testRead() { $this->setExpectedException('BadMethodCallException'); - $this->bodyStream->read(''); + $this->bodyStream->read(0); } public function testGetContents() @@ -152,7 +152,7 @@ public function testIsReadable() public function testSeek() { $this->setExpectedException('BadMethodCallException'); - $this->bodyStream->seek(''); + $this->bodyStream->seek(0); } public function testRewind()