From 1f53edb244754e76531b21c746c5e6d06e2d8313 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Thu, 4 Feb 2021 19:53:06 +0000 Subject: [PATCH 1/3] Modernize PHPStan configuration --- .github/workflows/test.yml | 7 +++---- composer.json | 2 +- phpstan.neon | 11 ++++------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9931ba049..18dbe990a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,11 +24,11 @@ jobs: tools: prestissimo env: COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - + - name: Get composer cache directory id: composercache run: echo "::set-output name=dir::$(composer config cache-files-dir)" - + - name: Cache dependencies uses: actions/cache@v2 with: @@ -46,7 +46,7 @@ jobs: - name: PHP Static Analysis Tool run: | - composer run-script phpstan + composer run-script phpstan -- --no-progress - name: Unit tests run: | @@ -71,4 +71,3 @@ jobs: vendor/bin/phpunit -c phpunit-integration-tests.xml env: TEST_SUITE: oss - \ No newline at end of file diff --git a/composer.json b/composer.json index f84b70271..8b94c277f 100644 --- a/composer.json +++ b/composer.json @@ -56,7 +56,7 @@ "phpcs --standard=ruleset.xml --extensions=php --encoding=utf-8 --tab-width=4 -sp tests" ], "phpstan": [ - "phpstan analyse src --level 2 --no-progress" + "phpstan analyse" ] } } diff --git a/phpstan.neon b/phpstan.neon index 8d3ed4325..6fc11e002 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,9 +1,6 @@ parameters: - reportUnmatchedIgnoredErrors: - false + level: 2 + paths: + - src/ ignoreErrors: - - '#Unsafe usage of new static\(\)#' - - '#Call to static method performRequest\(\) on trait#' - - '#Constant JSON_THROW_ON_ERROR not found#' - - '#Caught class JsonException not found#' - - '#Call to method getCode\(\) on an unknown class JsonException#' + - '#^Unsafe usage of new static\(\)\.$#' From 71dba3da7fba65a2f8f5df6a1d53517d2ed9f8e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Thu, 4 Feb 2021 20:19:00 +0000 Subject: [PATCH 2/3] Fix problems in Connection --- phpstan.neon | 4 ++++ src/Elasticsearch/Connections/Connection.php | 18 +++++++----------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 6fc11e002..c5f4cf5c4 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,6 +1,10 @@ parameters: + phpVersion: 70100 level: 2 paths: - src/ ignoreErrors: - '#^Unsafe usage of new static\(\)\.$#' + # PHP 7.1 only + - '#^Caught class JsonException not found\.$#' + - '#^Call to method getCode\(\) on an unknown class JsonException\.$#' diff --git a/src/Elasticsearch/Connections/Connection.php b/src/Elasticsearch/Connections/Connection.php index 661c9f6df..a5fb22b77 100644 --- a/src/Elasticsearch/Connections/Connection.php +++ b/src/Elasticsearch/Connections/Connection.php @@ -193,7 +193,7 @@ public function __construct( * @param Transport $transport * @return mixed */ - public function performRequest(string $method, string $uri, ?array $params = [], $body = null, array $options = [], Transport $transport = null) + public function performRequest(string $method, string $uri, array $params = [], $body = null, array $options = [], Transport $transport = null) { if ($body !== null) { $body = $this->serializer->serialize($body); @@ -337,9 +337,9 @@ private function wrapHandler(callable $handler): callable }; } - private function getURI(string $uri, ?array $params): string + private function getURI(string $uri, array $params): string { - if (isset($params) === true && !empty($params)) { + if ($params !== []) { array_walk( $params, function (&$value, &$key) { @@ -461,7 +461,7 @@ public function ping(): bool ] ]; try { - $response = $this->performRequest('HEAD', '/', null, null, $options); + $response = $this->performRequest('HEAD', '/', [], null, $options); $response = $response->wait(); } catch (TransportException $exception) { $this->markDead(); @@ -492,7 +492,7 @@ public function sniff() ] ]; - return $this->performRequest('GET', '/_nodes/', null, null, $options); + return $this->performRequest('GET', '/_nodes/', [], null, $options); } public function isAlive(): bool @@ -609,9 +609,7 @@ private function process4xxError(array $request, array $response, array $ignore) $statusCode = $response['status']; $responseBody = $response['body']; - /** - * @var \Exception $exception -*/ + /** @var \Exception $exception */ $exception = $this->tryDeserialize400Error($response); if (array_search($response['status'], $ignore) !== false) { @@ -647,9 +645,7 @@ private function process5xxError(array $request, array $response, array $ignore) $statusCode = (int) $response['status']; $responseBody = $response['body']; - /** - * @var \Exception $exception -*/ + /** @var \Exception $exception */ $exception = $this->tryDeserialize500Error($response); $exceptionText = "[$statusCode Server Exception] ".$exception->getMessage(); From 286e4361435fc0fa99c51234d01326695ecf10de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Thu, 4 Feb 2021 20:22:45 +0000 Subject: [PATCH 3/3] Run PHPStan only on PHP 7.1 --- .github/workflows/test.yml | 44 ++++++++++++++++++++++++++++++++++---- phpstan.neon | 1 + 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 18dbe990a..e5fa1b009 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -44,10 +44,6 @@ jobs: run: | composer run-script phpcs - - name: PHP Static Analysis Tool - run: | - composer run-script phpstan -- --no-progress - - name: Unit tests run: | vendor/bin/phpunit -c phpunit.xml.dist @@ -71,3 +67,43 @@ jobs: vendor/bin/phpunit -c phpunit-integration-tests.xml env: TEST_SUITE: oss + + phpstan: + name: Static Analysis + runs-on: ${{ matrix.os }} + + strategy: + matrix: + php-version: [7.1] + os: [ubuntu-latest] + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Use PHP ${{ matrix.php-version }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + tools: prestissimo + env: + COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Get composer cache directory + id: composercache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: ${{ steps.composercache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install dependencies + run: | + composer update --prefer-dist + + - name: PHP Static Analysis Tool + run: | + composer run-script phpstan -- --no-progress diff --git a/phpstan.neon b/phpstan.neon index c5f4cf5c4..8d54c3a7d 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -6,5 +6,6 @@ parameters: ignoreErrors: - '#^Unsafe usage of new static\(\)\.$#' # PHP 7.1 only + - '#^Constant JSON_THROW_ON_ERROR not found\.$#' - '#^Caught class JsonException not found\.$#' - '#^Call to method getCode\(\) on an unknown class JsonException\.$#'