diff --git a/src/HttpClient.php b/src/HttpClient.php index 0c5e895..f8e9831 100644 --- a/src/HttpClient.php +++ b/src/HttpClient.php @@ -1,7 +1,10 @@ withBody(StreamBuilder::build(substr($responseText, $headerSize))); } - /** - * @param string $endpoint - * @param array $headers - * @param string $body - * - * @return ResponseInterface - */ public function get(string $endpoint, array $headers = [], string $body = ''): ResponseInterface { return $this->buildAndSend('GET', $endpoint, $headers, $body); } - /** - * @param string $endpoint - * @param array $headers - * @param string $body - * - * @return ResponseInterface - */ public function post(string $endpoint, array $headers = [], string $body = ''): ResponseInterface { return $this->buildAndSend('POST', $endpoint, $headers, $body); } - /** - * @param string $endpoint - * @param array $headers - * @param string $body - * - * @return ResponseInterface - */ public function put(string $endpoint, array $headers = [], string $body = ''): ResponseInterface { return $this->buildAndSend('PUT', $endpoint, $headers, $body); } - /** - * @param string $endpoint - * @param array $headers - * @param string $body - * - * @return ResponseInterface - */ public function patch(string $endpoint, array $headers = [], string $body = ''): ResponseInterface { return $this->buildAndSend('PATCH', $endpoint, $headers, $body); } - /** - * @param string $endpoint - * @param array $headers - * @param string $body - * - * @return ResponseInterface - */ public function delete(string $endpoint, array $headers = [], string $body = ''): ResponseInterface { return $this->buildAndSend('DELETE', $endpoint, $headers, $body); } /** - * @param string $method - * @param string $endpoint - * @param array $headers - * @param string $body - * - * @return ResponseInterface + * @throws ClientExceptionInterface */ private function buildAndSend(string $method, string $endpoint, array $headers, string $body): ResponseInterface { @@ -104,11 +62,6 @@ class HttpClient implements ClientInterface return $this->sendRequest($request); } - /** - * @param string $endpoint - * - * @return UriInterface - */ private function buildUriFromEndpoint(string $endpoint): UriInterface { if (!parse_url($endpoint, PHP_URL_SCHEME)) { @@ -126,12 +79,6 @@ class HttpClient implements ClientInterface ); } - /** - * @param \CurlHandle $curl - * @param RequestInterface $request - * - * @return void - */ private function setCurlOptions(\CurlHandle &$curl, RequestInterface $request): void { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $request->getMethod()); @@ -145,10 +92,6 @@ class HttpClient implements ClientInterface } /** - * @param \CurlHandle $curl - * - * @return bool|string - * * @throws \RuntimeException */ private function getRawResponse(\CurlHandle &$curl): bool|string @@ -164,13 +107,6 @@ class HttpClient implements ClientInterface return $responseText; } - /** - * @param ResponseInterface $response - * @param string $responseText - * @param int $headerSize - * - * @return ResponseInterface - */ private function parseHeaders(ResponseInterface &$response, string $responseText, int $headerSize): ResponseInterface { $responseHeaders = substr($responseText, 0, $headerSize); diff --git a/src/Stream.php b/src/Stream.php index 86e92b9..5cbf21c 100644 --- a/src/Stream.php +++ b/src/Stream.php @@ -1,34 +1,27 @@ resource)) { throw new \InvalidArgumentException('Invalid resource provided for Stream'); } - $this->resource = $resource; $this->rewind(); } - /** - * @return string - */ public function __toString(): string { return $this->getContents(); } - /** - * @return void - */ public function close(): void { if (is_resource($this->resource)) { @@ -47,9 +40,6 @@ class Stream implements StreamInterface return $resource; } - /** - * @return int|null - */ public function getSize(): ?int { if (!$this->resource) { @@ -61,9 +51,6 @@ class Stream implements StreamInterface return $stats['size'] ?? null; } - /** - * @return int - */ public function tell(): int { if (!$this->resource) { @@ -79,9 +66,6 @@ class Stream implements StreamInterface return $position; } - /** - * @return bool - */ public function eof(): bool { if (!$this->resource) { @@ -91,9 +75,6 @@ class Stream implements StreamInterface return feof($this->resource); } - /** - * @return bool - */ public function isSeekable(): bool { if (!$this->resource) { @@ -105,12 +86,6 @@ class Stream implements StreamInterface return isset($meta['seekable']) && $meta['seekable']; } - /** - * @param int $offset - * @param int $whence - * - * @return void - */ public function seek(int $offset, int $whence = SEEK_SET): void { if (!$this->isSeekable()) { @@ -122,17 +97,11 @@ class Stream implements StreamInterface } } - /** - * @return void - */ public function rewind(): void { $this->seek(0); } - /** - * @return bool - */ public function isWritable(): bool { if (!$this->resource) { @@ -144,11 +113,6 @@ class Stream implements StreamInterface return isset($meta['mode']) && (str_contains($meta['mode'], 'w') || str_contains($meta['mode'], 'a')); } - /** - * @param string $string - * - * @return int - */ public function write(string $string): int { if (!$this->isWritable()) { @@ -164,9 +128,6 @@ class Stream implements StreamInterface return $result; } - /** - * @return bool - */ public function isReadable(): bool { if (!$this->resource) { @@ -178,11 +139,6 @@ class Stream implements StreamInterface return isset($meta['mode']) && (str_contains($meta['mode'], 'r') || str_contains($meta['mode'], 'a') || str_contains($meta['mode'], '+')); } - /** - * @param int $length - * - * @return string - */ public function read(int $length): string { if (!$this->isReadable()) { @@ -198,9 +154,6 @@ class Stream implements StreamInterface return $data; } - /** - * @return string - */ public function getContents(): string { if (!$this->isReadable()) { @@ -218,11 +171,6 @@ class Stream implements StreamInterface return $contents; } - /** - * @param mixed $key - * - * @return mixed - */ public function getMetadata(mixed $key = null): mixed { if (!$this->resource) { diff --git a/src/StreamBuilder.php b/src/StreamBuilder.php index 33c648e..4359955 100644 --- a/src/StreamBuilder.php +++ b/src/StreamBuilder.php @@ -1,16 +1,13 @@ scheme = $scheme; - $this->host = $host; + public function __construct( + private string $scheme, + private string $host, + private string $path, + private string $query, + string|int|null $port = null + ) { $this->port = (string) $port; - $this->path = $path; - $this->query = $query; $this->fragment = ''; $this->userInfo = ''; } - /** - * @return string - */ public function getScheme(): string { return $this->scheme; } - /** - * @return string - */ public function getAuthority(): string { $authority = $this->host; @@ -51,59 +44,36 @@ class Uri implements UriInterface return $authority; } - /** - * @return string - */ public function getUserInfo(): string { return $this->userInfo; } - /** - * @return string - */ public function getHost(): string { return $this->host; } - /** - * @return int|null - */ public function getPort(): ?int { return (int) $this->port; } - /** - * @return string - */ public function getPath(): string { return $this->path; } - /** - * @return string - */ public function getQuery(): string { return $this->query; } - /** - * @return string - */ public function getFragment(): string { return $this->fragment; } - /** - * @param string $scheme - * - * @return UriInterface - */ public function withScheme(string $scheme): UriInterface { $uri = clone $this; @@ -112,12 +82,6 @@ class Uri implements UriInterface return $uri; } - /** - * @param string $user - * @param string|null $password - * - * @return UriInterface - */ public function withUserInfo(string $user, ?string $password = null): UriInterface { $uri = clone $this; @@ -126,11 +90,6 @@ class Uri implements UriInterface return $uri; } - /** - * @param string $host - * - * @return UriInterface - */ public function withHost(string $host): UriInterface { $uri = clone $this; @@ -139,24 +98,14 @@ class Uri implements UriInterface return $uri; } - /** - * @param int|null $port - * - * @return UriInterface - */ public function withPort(?int $port): UriInterface { $uri = clone $this; - $uri->port = $port; + $uri->port = (string) $port; return $uri; } - /** - * @param string $path - * - * @return UriInterface - */ public function withPath(string $path): UriInterface { $uri = clone $this; @@ -165,11 +114,6 @@ class Uri implements UriInterface return $uri; } - /** - * @param string $query - * - * @return UriInterface - */ public function withQuery(string $query): UriInterface { $uri = clone $this; @@ -178,11 +122,6 @@ class Uri implements UriInterface return $uri; } - /** - * @param string $fragment - * - * @return UriInterface - */ public function withFragment(string $fragment): UriInterface { $uri = clone $this; @@ -191,9 +130,6 @@ class Uri implements UriInterface return $uri; } - /** - * @return string - */ public function __toString(): string { $uri = sprintf('%s://%s', $this->scheme, $this->host); diff --git a/src/Web/WebServerUri.php b/src/Web/WebServerUri.php index 34f6914..07856f1 100644 --- a/src/Web/WebServerUri.php +++ b/src/Web/WebServerUri.php @@ -1,14 +1,13 @@ getWritableStreamWithData(); @@ -19,9 +18,6 @@ class StreamTest extends TestCase $stream->close(); } - /** - * @return void - */ public function testGetSize(): void { [$stream, $data] = $this->getWritableStreamWithData(); @@ -31,9 +27,6 @@ class StreamTest extends TestCase $stream->close(); } - /** - * @return void - */ public function testTell(): void { [$stream] = $this->getWritableStreamWithData(); @@ -45,9 +38,6 @@ class StreamTest extends TestCase $stream->close(); } - /** - * @return void - */ public function testClose(): void { $resource = fopen('php://temp', 'r+'); @@ -60,9 +50,6 @@ class StreamTest extends TestCase $this->assertFalse(is_resource($resource)); } - /** - * @return void - */ public function testDetach(): void { $resource = fopen('php://temp', 'r+'); @@ -76,9 +63,6 @@ class StreamTest extends TestCase $stream->close(); } - /** - * @return void - */ public function testEof(): void { [$stream, $data] = $this->getWritableStreamWithData(); @@ -92,9 +76,6 @@ class StreamTest extends TestCase $stream->close(); } - /** - * @return void - */ public function testIsSeekableWithSeekableResource(): void { [$stream] = $this->getWritableStreamWithData(); @@ -104,9 +85,6 @@ class StreamTest extends TestCase $stream->close(); } - /** - * @return void - */ public function testSeek(): void { [$stream] = $this->getWritableStreamWithData(); @@ -118,9 +96,6 @@ class StreamTest extends TestCase $stream->close(); } - /** - * @return void - */ public function testRead(): void { [$stream] = $this->getWritableStreamWithData(); @@ -136,9 +111,6 @@ class StreamTest extends TestCase $this->assertSame('', $read[2]); } - /** - * @return void - */ public function testWrite(): void { $resource = fopen('php://temp', 'r+'); @@ -155,9 +127,6 @@ class StreamTest extends TestCase $stream->close(); } - /** - * @return void - */ public function testGetMetadata(): void { [$stream] = $this->getWritableStreamWithData(); @@ -167,9 +136,6 @@ class StreamTest extends TestCase $stream->close(); } - /** - * @return array - */ private function getWritableStreamWithData(): array { $data = 'Test string'; diff --git a/tests/UriTest.php b/tests/UriTest.php index 4bfdb7a..4625d7f 100644 --- a/tests/UriTest.php +++ b/tests/UriTest.php @@ -1,5 +1,7 @@ assertEquals('https', ($this->getDefaultUri())->getScheme()); } - /** - * @return void - */ public function testGetAuthority(): void { $uri = new Uri('https', 'test.com', '/path', 'var=1', 443); @@ -28,26 +24,17 @@ class UriTest extends TestCase $this->assertEquals('user:password@test.com', $uri->getAuthority()); } - /** - * @return void - */ public function testWithPath(): void { $this->assertEquals('/', ($this->getDefaultUri())->getPath()); $this->assertEquals('/new', ($this->getDefaultUri())->withPath('/new')->getPath()); } - /** - * @return void - */ public function testToString(): void { $this->assertEquals('https://test.com/', ($this->getDefaultUri())->__toString()); } - /** - * @return void - */ public function testWithUserInfo(): void { $this->assertEquals( @@ -56,33 +43,21 @@ class UriTest extends TestCase ); } - /** - * @return void - */ public function testWithScheme(): void { $this->assertEquals('ftp', ($this->getDefaultUri())->withScheme('ftp')->getScheme()); } - /** - * @return void - */ public function testWithHost(): void { $this->assertEquals('localhost', ($this->getDefaultUri())->withHost('localhost')->getHost()); } - /** - * @return void - */ public function testWithPort(): void { $this->assertEquals(8080, ($this->getDefaultUri())->withPort(8080)->getPort()); } - /** - * @return void - */ public function testWithQuery(): void { $this->assertEquals( @@ -91,17 +66,11 @@ class UriTest extends TestCase ); } - /** - * @return void - */ public function testWithFragment(): void { $this->assertEquals('news', ($this->getDefaultUri())->withFragment('news')->getFragment()); } - /** - * @return UriInterface - */ private function getDefaultUri(): UriInterface { return new Uri('https', 'test.com', '/', '');