From de35d3fba41c6d98cb55fb05f118736d2f76cd67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ste=CC=81phane=20HULARD?= Date: Thu, 17 Dec 2020 16:49:45 +0100 Subject: [PATCH 1/2] chore(static): Add PHPStan configuration. Also fix static errors in Promise. --- phpstan.neon.dist | 4 ++++ src/Promise.php | 9 +++++---- 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 phpstan.neon.dist diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..776ccd8 --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,4 @@ +parameters: + level: max + paths: + - src diff --git a/src/Promise.php b/src/Promise.php index f522d65..ec7d852 100644 --- a/src/Promise.php +++ b/src/Promise.php @@ -30,14 +30,14 @@ final class Promise implements HttpPromise /** * PSR7 received response. * - * @var ResponseInterface + * @var ResponseInterface|null */ private $response; /** * Execution error. * - * @var Exception + * @var HttplugException */ private $exception; @@ -69,7 +69,7 @@ public function __construct(PromiseInterface $promise, LoopInterface $loop, Requ $this->request = $request; $this->loop = $loop; $this->promise = $promise->then( - function (?ResponseInterface $response): ResponseInterface { + function (?ResponseInterface $response): ?ResponseInterface { $this->response = $response; $this->state = self::FULFILLED; @@ -92,7 +92,8 @@ function ($reason): void { } throw $this->exception; - }); + } + ); } public function then(?callable $onFulfilled = null, ?callable $onRejected = null) From 1189d92753b116032f42de5ec264d90e3f8718b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ste=CC=81phane=20HULARD?= Date: Thu, 17 Dec 2020 16:52:39 +0100 Subject: [PATCH 2/2] chore(sniff): Refine PHPCodeSniffer configuration. Also fix the PHP code by applying the sniff rules. --- .php_cs | 13 ------------- .php_cs.dist | 14 ++++++++++++++ src/Client.php | 2 +- src/ReactFactory.php | 6 +++--- tests/AsyncClientTest.php | 2 +- tests/ClientTest.php | 2 +- 6 files changed, 20 insertions(+), 19 deletions(-) delete mode 100644 .php_cs create mode 100644 .php_cs.dist diff --git a/.php_cs b/.php_cs deleted file mode 100644 index 23ba165..0000000 --- a/.php_cs +++ /dev/null @@ -1,13 +0,0 @@ -exclude('vendor') + ->in(__DIR__) +; + +return PhpCsFixer\Config::create() + ->setRules([ + '@Symfony' => true, + 'array_syntax' => ['syntax' => 'short'], + ]) + ->setFinder($finder); diff --git a/src/Client.php b/src/Client.php index 34570c5..35ded8c 100644 --- a/src/Client.php +++ b/src/Client.php @@ -2,8 +2,8 @@ namespace Http\Adapter\React; -use Http\Client\HttpClient; use Http\Client\HttpAsyncClient; +use Http\Client\HttpClient; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use React\EventLoop\LoopInterface; diff --git a/src/ReactFactory.php b/src/ReactFactory.php index 08085c0..62dbe94 100644 --- a/src/ReactFactory.php +++ b/src/ReactFactory.php @@ -2,8 +2,8 @@ namespace Http\Adapter\React; -use React\EventLoop\LoopInterface; use React\EventLoop\Factory as EventLoopFactory; +use React\EventLoop\LoopInterface; use React\Http\Browser; use React\Socket\ConnectorInterface; @@ -25,8 +25,8 @@ public static function buildEventLoop(): LoopInterface /** * Build a React Http Client. * - * @param ConnectorInterface|null $connector Only pass this argument if you need to customize DNS - * behaviour. + * @param ConnectorInterface|null $connector only pass this argument if you need to customize DNS + * behaviour */ public static function buildHttpClient( LoopInterface $loop, diff --git a/tests/AsyncClientTest.php b/tests/AsyncClientTest.php index bcf9540..7ab4d63 100644 --- a/tests/AsyncClientTest.php +++ b/tests/AsyncClientTest.php @@ -2,9 +2,9 @@ namespace Http\Adapter\React\Tests; -use Http\Client\Tests\HttpAsyncClientTest; use Http\Adapter\React\Client; use Http\Client\HttpAsyncClient; +use Http\Client\Tests\HttpAsyncClientTest; /** * @author Stéphane Hulard diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 57c6614..e2ef2ac 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -2,8 +2,8 @@ namespace Http\Adapter\React\Tests; -use Http\Client\Tests\HttpClientTest; use Http\Adapter\React\Client; +use Http\Client\Tests\HttpClientTest; use Psr\Http\Client\ClientInterface; /**