diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9931ba049..e5fa1b009 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: @@ -44,10 +44,6 @@ jobs: run: | composer run-script phpcs - - name: PHP Static Analysis Tool - run: | - composer run-script phpstan - - name: Unit tests run: | vendor/bin/phpunit -c phpunit.xml.dist @@ -71,4 +67,43 @@ jobs: vendor/bin/phpunit -c phpunit-integration-tests.xml env: TEST_SUITE: oss - \ No newline at end of file + + 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/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..8d54c3a7d 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,9 +1,11 @@ parameters: - reportUnmatchedIgnoredErrors: - false + phpVersion: 70100 + 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\(\)\.$#' + # 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\.$#' 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();