diff --git a/composer.json b/composer.json index 5ea7fe4..0dc4761 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "sabre/uri" : "^2.3" }, "require-dev" : { - "friendsofphp/php-cs-fixer": "^3.38", + "friendsofphp/php-cs-fixer": "^3.54", "phpstan/phpstan": "^1.10", "phpunit/phpunit" : "^9.6" }, @@ -60,5 +60,10 @@ "composer cs-fixer", "composer phpunit" ] + }, + "config": { + "allow-plugins": { + "phpstan/extension-installer": true + } } } diff --git a/examples/stringify.php b/examples/stringify.php index 96f7da8..8ceefe2 100644 --- a/examples/stringify.php +++ b/examples/stringify.php @@ -30,7 +30,7 @@ $request->setHeaders([ 'Host' => 'example.org', 'Content-Type' => 'application/json', - ]); +]); $request->setBody(json_encode(['foo' => 'bar'])); @@ -41,7 +41,7 @@ $response->setHeaders([ 'Content-Type' => 'text/plain', 'Connection' => 'close', - ]); +]); $response->setBody('ABORT! ABORT!'); diff --git a/lib/Client.php b/lib/Client.php index b73bf73..f94d933 100644 --- a/lib/Client.php +++ b/lib/Client.php @@ -177,7 +177,7 @@ public function send(RequestInterface $request): ResponseInterface * After calling sendAsync, you must therefore occasionally call the poll() * method, or wait(). */ - public function sendAsync(RequestInterface $request, callable $success = null, callable $error = null): void + public function sendAsync(RequestInterface $request, ?callable $success = null, ?callable $error = null): void { $this->emit('beforeRequest', [$request]); $this->sendAsyncInternal($request, $success, $error); diff --git a/lib/Response.php b/lib/Response.php index 19ac87b..934d724 100644 --- a/lib/Response.php +++ b/lib/Response.php @@ -101,7 +101,7 @@ class Response extends Message implements ResponseInterface * @param array|null $headers * @param resource|string|callable|null $body */ - public function __construct($status = 500, array $headers = null, $body = null) + public function __construct($status = 500, ?array $headers = null, $body = null) { if (null !== $status) { $this->setStatus($status); diff --git a/tests/HTTP/ClientTest.php b/tests/HTTP/ClientTest.php index 4c1d5dc..61ed840 100644 --- a/tests/HTTP/ClientTest.php +++ b/tests/HTTP/ClientTest.php @@ -14,15 +14,15 @@ public function testCreateCurlSettingsArrayGET(): void $request = new Request('GET', 'http://example.org/', ['X-Foo' => 'bar']); $settings = [ - CURLOPT_RETURNTRANSFER => true, - CURLOPT_HEADER => true, - CURLOPT_POSTREDIR => 0, - CURLOPT_HTTPHEADER => ['X-Foo: bar'], - CURLOPT_NOBODY => false, - CURLOPT_URL => 'http://example.org/', - CURLOPT_CUSTOMREQUEST => 'GET', - CURLOPT_USERAGENT => 'sabre-http/'.Version::VERSION.' (http://sabre.io/)', - ]; + CURLOPT_RETURNTRANSFER => true, + CURLOPT_HEADER => true, + CURLOPT_POSTREDIR => 0, + CURLOPT_HTTPHEADER => ['X-Foo: bar'], + CURLOPT_NOBODY => false, + CURLOPT_URL => 'http://example.org/', + CURLOPT_CUSTOMREQUEST => 'GET', + CURLOPT_USERAGENT => 'sabre-http/'.Version::VERSION.' (http://sabre.io/)', + ]; // FIXME: CURLOPT_PROTOCOLS and CURLOPT_REDIR_PROTOCOLS are currently unsupported by HHVM // at least if this unit test fails in the future we know it is :) @@ -67,14 +67,14 @@ public function testCreateCurlSettingsArrayHEAD(): void $request = new Request('HEAD', 'http://example.org/', ['X-Foo' => 'bar']); $settings = [ - CURLOPT_RETURNTRANSFER => true, - CURLOPT_HEADER => true, - CURLOPT_NOBODY => true, - CURLOPT_CUSTOMREQUEST => 'HEAD', - CURLOPT_HTTPHEADER => ['X-Foo: bar'], - CURLOPT_URL => 'http://example.org/', - CURLOPT_USERAGENT => 'sabre-http/'.Version::VERSION.' (http://sabre.io/)', - ]; + CURLOPT_RETURNTRANSFER => true, + CURLOPT_HEADER => true, + CURLOPT_NOBODY => true, + CURLOPT_CUSTOMREQUEST => 'HEAD', + CURLOPT_HTTPHEADER => ['X-Foo: bar'], + CURLOPT_URL => 'http://example.org/', + CURLOPT_USERAGENT => 'sabre-http/'.Version::VERSION.' (http://sabre.io/)', + ]; // FIXME: CURLOPT_PROTOCOLS and CURLOPT_REDIR_PROTOCOLS are currently unsupported by HHVM // at least if this unit test fails in the future we know it is :) @@ -100,14 +100,14 @@ public function testCreateCurlSettingsArrayGETAfterHEAD(): void $request = new Request('GET', 'http://example.org/', ['X-Foo' => 'bar']); $settings = [ - CURLOPT_CUSTOMREQUEST => 'GET', - CURLOPT_RETURNTRANSFER => true, - CURLOPT_HEADER => true, - CURLOPT_HTTPHEADER => ['X-Foo: bar'], - CURLOPT_NOBODY => false, - CURLOPT_URL => 'http://example.org/', - CURLOPT_USERAGENT => 'sabre-http/'.Version::VERSION.' (http://sabre.io/)', - ]; + CURLOPT_CUSTOMREQUEST => 'GET', + CURLOPT_RETURNTRANSFER => true, + CURLOPT_HEADER => true, + CURLOPT_HTTPHEADER => ['X-Foo: bar'], + CURLOPT_NOBODY => false, + CURLOPT_URL => 'http://example.org/', + CURLOPT_USERAGENT => 'sabre-http/'.Version::VERSION.' (http://sabre.io/)', + ]; // FIXME: CURLOPT_PROTOCOLS and CURLOPT_REDIR_PROTOCOLS are currently unsupported by HHVM // at least if this unit test fails in the future we know it is :) @@ -129,17 +129,17 @@ public function testCreateCurlSettingsArrayPUTStream(): void $request = new Request('PUT', 'http://example.org/', ['X-Foo' => 'bar'], $h); $settings = [ - CURLOPT_RETURNTRANSFER => true, - CURLOPT_HEADER => true, - CURLOPT_PUT => true, - CURLOPT_INFILE => $h, - CURLOPT_INFILESIZE => strlen($fileContent), - CURLOPT_NOBODY => false, - CURLOPT_CUSTOMREQUEST => 'PUT', - CURLOPT_HTTPHEADER => ['X-Foo: bar'], - CURLOPT_URL => 'http://example.org/', - CURLOPT_USERAGENT => 'sabre-http/'.Version::VERSION.' (http://sabre.io/)', - ]; + CURLOPT_RETURNTRANSFER => true, + CURLOPT_HEADER => true, + CURLOPT_PUT => true, + CURLOPT_INFILE => $h, + CURLOPT_INFILESIZE => strlen($fileContent), + CURLOPT_NOBODY => false, + CURLOPT_CUSTOMREQUEST => 'PUT', + CURLOPT_HTTPHEADER => ['X-Foo: bar'], + CURLOPT_URL => 'http://example.org/', + CURLOPT_USERAGENT => 'sabre-http/'.Version::VERSION.' (http://sabre.io/)', + ]; // FIXME: CURLOPT_PROTOCOLS and CURLOPT_REDIR_PROTOCOLS are currently unsupported by HHVM // at least if this unit test fails in the future we know it is :) @@ -157,15 +157,15 @@ public function testCreateCurlSettingsArrayPUTString(): void $request = new Request('PUT', 'http://example.org/', ['X-Foo' => 'bar'], 'boo'); $settings = [ - CURLOPT_RETURNTRANSFER => true, - CURLOPT_HEADER => true, - CURLOPT_NOBODY => false, - CURLOPT_POSTFIELDS => 'boo', - CURLOPT_CUSTOMREQUEST => 'PUT', - CURLOPT_HTTPHEADER => ['X-Foo: bar'], - CURLOPT_URL => 'http://example.org/', - CURLOPT_USERAGENT => 'sabre-http/'.Version::VERSION.' (http://sabre.io/)', - ]; + CURLOPT_RETURNTRANSFER => true, + CURLOPT_HEADER => true, + CURLOPT_NOBODY => false, + CURLOPT_POSTFIELDS => 'boo', + CURLOPT_CUSTOMREQUEST => 'PUT', + CURLOPT_HTTPHEADER => ['X-Foo: bar'], + CURLOPT_URL => 'http://example.org/', + CURLOPT_USERAGENT => 'sabre-http/'.Version::VERSION.' (http://sabre.io/)', + ]; // FIXME: CURLOPT_PROTOCOLS and CURLOPT_REDIR_PROTOCOLS are currently unsupported by HHVM // at least if this unit test fails in the future we know it is :) diff --git a/tests/HTTP/MessageDecoratorTest.php b/tests/HTTP/MessageDecoratorTest.php index b5e1aa2..bc3e73e 100644 --- a/tests/HTTP/MessageDecoratorTest.php +++ b/tests/HTTP/MessageDecoratorTest.php @@ -30,7 +30,7 @@ public function testHeaders(): void { $this->outer->setHeaders([ 'a' => 'b', - ]); + ]); $this->assertEquals(['a' => ['b']], $this->inner->getHeaders()); $this->assertEquals(['a' => ['b']], $this->outer->getHeaders()); @@ -44,7 +44,7 @@ public function testHeaders(): void $this->outer->addHeaders([ 'e' => 'f', - ]); + ]); $this->assertEquals(['a' => ['b'], 'c' => ['d'], 'e' => ['f']], $this->inner->getHeaders()); $this->assertEquals(['a' => ['b'], 'c' => ['d'], 'e' => ['f']], $this->outer->getHeaders());