Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize PHPStan configuration #1103

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 42 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -71,4 +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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
}
16 changes: 9 additions & 7 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -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\.$#'
18 changes: 7 additions & 11 deletions src/Elasticsearch/Connections/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 !== []) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverting to array only.
BTW empty internally does isset.

array_walk(
$params,
function (&$value, &$key) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down