From 79c2e65e304a9f6dc58c0e1dfbef6663a52672ad Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Wed, 13 Jul 2022 07:49:25 +0200 Subject: [PATCH] fix static analysis --- .gitattributes | 23 ++++++++--------------- .github/workflows/ci.yml | 2 ++ .github/workflows/static.yml | 2 +- .gitignore | 3 +-- .php-cs-fixer.dist.php | 16 ++++++++++++++++ .php_cs.dist | 14 -------------- phpstan.neon.dist | 3 +++ src/Client.php | 2 ++ tests/PromiseTest.php | 8 ++++---- 9 files changed, 37 insertions(+), 36 deletions(-) create mode 100644 .php-cs-fixer.dist.php delete mode 100644 .php_cs.dist diff --git a/.gitattributes b/.gitattributes index c47225a..c1e187c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,15 +1,8 @@ -.editorconfig export-ignore -.gitattributes export-ignore -/.github/ export-ignore -.gitignore export-ignore -/.php_cs export-ignore -/.scrutinizer.yml export-ignore -/.styleci.yml export-ignore -/.travis.yml export-ignore -/behat.yml.dist export-ignore -/features/ export-ignore -/phpspec.ci.yml export-ignore -/phpspec.yml.dist export-ignore -/phpunit.xml.dist export-ignore -/spec/ export-ignore -/tests/ export-ignore +.editorconfig export-ignore +.gitattributes export-ignore +/.github/ export-ignore +.gitignore export-ignore +/.php-cs-fixer.dist.php export-ignore +/phpstan.neon.dist export-ignore +/phpunit.xml.dist export-ignore +/tests/ export-ignore diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e617889..f24df12 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,6 +2,8 @@ name: CI on: push: + branches: + - master pull_request: jobs: diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index b2f69cf..f4aa6f6 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -33,4 +33,4 @@ jobs: - name: PHP-CS-Fixer uses: docker://oskarstark/php-cs-fixer-ga with: - args: --dry-run --diff-format udiff + args: --dry-run --diff diff --git a/.gitignore b/.gitignore index e1c991d..14e2bd0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ -/behat.yml /build/ /composer.lock -/phpspec.yml /phpunit.xml /vendor/ +.php-cs-fixer.php .phpunit.result.cache diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..bcb9a69 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,16 @@ +exclude('vendor') + ->in(__DIR__) +; + +$config = (new PhpCsFixer\Config()) + ->setRiskyAllowed(true) + ->setRules([ + '@Symfony' => true, + ]) + ->setFinder($finder) +; + +return $config; diff --git a/.php_cs.dist b/.php_cs.dist deleted file mode 100644 index 8032bb8..0000000 --- a/.php_cs.dist +++ /dev/null @@ -1,14 +0,0 @@ - -exclude('vendor') - ->in(__DIR__) -; - -return PhpCsFixer\Config::create() - ->setRules([ - '@Symfony' => true, - 'array_syntax' => ['syntax' => 'short'], - ]) - ->setFinder($finder); diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 776ccd8..d6f0fbe 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -2,3 +2,6 @@ parameters: level: max paths: - src + ignoreErrors: + - message: '#^Method Http\\Adapter\\React\\Client::sendRequest\(\) should return Psr\\Http\\Message\\ResponseInterface but returns mixed.$#' + path: src/Client.php diff --git a/src/Client.php b/src/Client.php index 35ded8c..fc11669 100644 --- a/src/Client.php +++ b/src/Client.php @@ -52,6 +52,8 @@ public function sendRequest(RequestInterface $request): ResponseInterface { $promise = $this->sendAsyncRequest($request); + // The promise is declared to return mixed, but the react client promise returns a response. + // We unwrap the exception if there is any, otherwise the promise would return null on error. return $promise->wait(); } diff --git a/tests/PromiseTest.php b/tests/PromiseTest.php index 1684e91..288630c 100644 --- a/tests/PromiseTest.php +++ b/tests/PromiseTest.php @@ -71,11 +71,11 @@ public function exceptionThatIsThrownFromReactProvider() $response = $this->getMockBuilder(ResponseInterface::class)->getMock(); return [ - 'string' => [$request, 'whatever', UnexpectedValueException::class], + 'string' => [$request, 'whatever', UnexpectedValueException::class], 'InvalidArgumentException' => [$request, new InvalidArgumentException('Something went wrong'), TransferException::class], - 'RuntimeException' => [$request, new RuntimeException('Something happened inside ReactPHP engine'), NetworkException::class], - 'NetworkException' => [$request, new NetworkException('Something happened inside ReactPHP engine', $request), NetworkException::class], - 'HttpException' => [$request, new HttpException('Something happened inside ReactPHP engine', $request, $response), HttpException::class], + 'RuntimeException' => [$request, new RuntimeException('Something happened inside ReactPHP engine'), NetworkException::class], + 'NetworkException' => [$request, new NetworkException('Something happened inside ReactPHP engine', $request), NetworkException::class], + 'HttpException' => [$request, new HttpException('Something happened inside ReactPHP engine', $request, $response), HttpException::class], ]; } }