Skip to content

Commit 4679184

Browse files
committed
Fixed CS issues
1 parent 9a42205 commit 4679184

File tree

380 files changed

+763
-1196
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

380 files changed

+763
-1196
lines changed

src/Elasticsearch/Client.php

Lines changed: 76 additions & 81 deletions
Large diffs are not rendered by default.

src/Elasticsearch/ClientBuilder.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class ClientBuilder
134134
private $sslVerification = null;
135135

136136
/**
137-
* @var bool
137+
* @var bool
138138
*/
139139
private $includePortInHostHeader = false;
140140

@@ -345,7 +345,6 @@ public function setHosts(array $hosts): ClientBuilder
345345
/**
346346
* Set the APIKey Pair, consiting of the API Id and the ApiKey of the Response from /_security/api_key
347347
*
348-
*
349348
* @throws AuthenticationConfigException
350349
*/
351350
public function setApiKey(string $id, string $apiKey): ClientBuilder
@@ -390,19 +389,20 @@ public function setBasicAuthentication(string $username, string $password): Clie
390389
/**
391390
* Set Elastic Cloud ID to connect to Elastic Cloud
392391
*
393-
*
394392
* @param string $cloudId
395393
*/
396394
public function setElasticCloudId(string $cloudId): ClientBuilder
397395
{
398396
// Register the Hosts array
399-
$this->setHosts([
397+
$this->setHosts(
398+
[
400399
[
401400
'host' => $this->parseElasticCloudId($cloudId),
402401
'port' => '',
403402
'scheme' => 'https',
404403
]
405-
]);
404+
]
405+
);
406406

407407
if (!isset($this->connectionParams['client']['curl'][CURLOPT_ENCODING])) {
408408
// Merge best practices for the connection (enable gzip)
@@ -464,7 +464,7 @@ public function setSSLKey(string $key, string $password = null): ClientBuilder
464464
}
465465

466466
/**
467-
* @param bool|string $value
467+
* @param bool|string $value
468468
*/
469469
public function setSSLVerification($value = true): ClientBuilder
470470
{
@@ -475,6 +475,7 @@ public function setSSLVerification($value = true): ClientBuilder
475475

476476
/**
477477
* Include the port in Host header
478+
*
478479
* @see https://github.com/elastic/elasticsearch-php/issues/993
479480
*/
480481
public function includePortInHostHeader(bool $enable): ClientBuilder

src/Elasticsearch/Common/EmptyLogger.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
*
2727
* Logger that doesn't do anything. Similar to Monolog's NullHandler,
2828
* but avoids the overhead of partially loading Monolog
29-
*
3029
*/
3130
class EmptyLogger extends AbstractLogger implements LoggerInterface
3231
{

src/Elasticsearch/Common/Exceptions/BadMethodCallException.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
* BadMethodCallException
2323
*
2424
* Denote problems with a method call (e.g. incorrect number of arguments)
25-
*
2625
*/
2726
class BadMethodCallException extends \BadMethodCallException implements ElasticsearchException
2827
{

src/Elasticsearch/Common/Exceptions/Serializer/JsonErrorException.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
/**
2424
* Class JsonErrorException
25-
*
2625
*/
2726
class JsonErrorException extends \Exception implements ElasticsearchException
2827
{

src/Elasticsearch/Connections/Connection.php

Lines changed: 85 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ class Connection implements ConnectionInterface
7070
protected $path;
7171

7272
/**
73-
* @var int
74-
*/
73+
* @var int
74+
*/
7575
protected $port;
7676

7777
/**
@@ -143,9 +143,10 @@ public function __construct(
143143

144144
// Only Set the Basic if API Key is not set and setBasicAuthentication was not called prior
145145
if (isset($connectionParams['client']['headers']['Authorization']) === false
146-
&& isset($connectionParams['client']['curl'][CURLOPT_HTTPAUTH]) === false
147-
&& isset($hostDetails['user'])
148-
&& isset($hostDetails['pass'])) {
146+
&& isset($connectionParams['client']['curl'][CURLOPT_HTTPAUTH]) === false
147+
&& isset($hostDetails['user'])
148+
&& isset($hostDetails['pass'])
149+
) {
149150
$connectionParams['client']['curl'][CURLOPT_HTTPAUTH] = CURLAUTH_BASIC;
150151
$connectionParams['client']['curl'][CURLOPT_USERPWD] = $hostDetails['user'].':'.$hostDetails['pass'];
151152
}
@@ -252,86 +253,89 @@ private function wrapHandler(callable $handler): callable
252253
$this->lastRequest['request'] = $request;
253254

254255
// Send the request using the wrapped handler.
255-
$response = Core::proxy($handler($request), function ($response) use ($connection, $transport, $request, $options) {
256-
257-
$this->lastRequest['response'] = $response;
258-
259-
if (isset($response['error']) === true) {
260-
if ($response['error'] instanceof ConnectException || $response['error'] instanceof RingException) {
261-
$this->log->warning("Curl exception encountered.");
262-
263-
$exception = $this->getCurlRetryException($request, $response);
264-
265-
$this->logRequestFail($request, $response, $exception);
266-
267-
$node = $connection->getHost();
268-
$this->log->warning("Marking node $node dead.");
269-
$connection->markDead();
270-
271-
// If the transport has not been set, we are inside a Ping or Sniff,
272-
// so we don't want to retrigger retries anyway.
273-
//
274-
// TODO this could be handled better, but we are limited because connectionpools do not
275-
// have access to Transport. Architecturally, all of this needs to be refactored
276-
if (isset($transport) === true) {
277-
$transport->connectionPool->scheduleCheck();
278-
279-
$neverRetry = isset($request['client']['never_retry']) ? $request['client']['never_retry'] : false;
280-
$shouldRetry = $transport->shouldRetry($request);
281-
$shouldRetryText = ($shouldRetry) ? 'true' : 'false';
282-
283-
$this->log->warning("Retries left? $shouldRetryText");
284-
if ($shouldRetry && !$neverRetry) {
285-
return $transport->performRequest(
286-
$request['http_method'],
287-
$request['uri'],
288-
[],
289-
$request['body'],
290-
$options
291-
);
256+
$response = Core::proxy(
257+
$handler($request),
258+
function ($response) use ($connection, $transport, $request, $options) {
259+
260+
$this->lastRequest['response'] = $response;
261+
262+
if (isset($response['error']) === true) {
263+
if ($response['error'] instanceof ConnectException || $response['error'] instanceof RingException) {
264+
$this->log->warning("Curl exception encountered.");
265+
266+
$exception = $this->getCurlRetryException($request, $response);
267+
268+
$this->logRequestFail($request, $response, $exception);
269+
270+
$node = $connection->getHost();
271+
$this->log->warning("Marking node $node dead.");
272+
$connection->markDead();
273+
274+
// If the transport has not been set, we are inside a Ping or Sniff,
275+
// so we don't want to retrigger retries anyway.
276+
//
277+
// TODO this could be handled better, but we are limited because connectionpools do not
278+
// have access to Transport. Architecturally, all of this needs to be refactored
279+
if (isset($transport) === true) {
280+
$transport->connectionPool->scheduleCheck();
281+
282+
$neverRetry = isset($request['client']['never_retry']) ? $request['client']['never_retry'] : false;
283+
$shouldRetry = $transport->shouldRetry($request);
284+
$shouldRetryText = ($shouldRetry) ? 'true' : 'false';
285+
286+
$this->log->warning("Retries left? $shouldRetryText");
287+
if ($shouldRetry && !$neverRetry) {
288+
return $transport->performRequest(
289+
$request['http_method'],
290+
$request['uri'],
291+
[],
292+
$request['body'],
293+
$options
294+
);
295+
}
292296
}
293-
}
294297

295-
$this->log->warning("Out of retries, throwing exception from $node");
296-
// Only throw if we run out of retries
297-
throw $exception;
298+
$this->log->warning("Out of retries, throwing exception from $node");
299+
// Only throw if we run out of retries
300+
throw $exception;
301+
} else {
302+
// Something went seriously wrong, bail
303+
$exception = new TransportException($response['error']->getMessage());
304+
$this->logRequestFail($request, $response, $exception);
305+
throw $exception;
306+
}
298307
} else {
299-
// Something went seriously wrong, bail
300-
$exception = new TransportException($response['error']->getMessage());
301-
$this->logRequestFail($request, $response, $exception);
302-
throw $exception;
303-
}
304-
} else {
305-
$connection->markAlive();
308+
$connection->markAlive();
306309

307-
if (isset($response['headers']['Warning'])) {
308-
$this->logWarning($request, $response);
309-
}
310-
if (isset($response['body']) === true) {
311-
$response['body'] = stream_get_contents($response['body']);
312-
$this->lastRequest['response']['body'] = $response['body'];
313-
}
310+
if (isset($response['headers']['Warning'])) {
311+
$this->logWarning($request, $response);
312+
}
313+
if (isset($response['body']) === true) {
314+
$response['body'] = stream_get_contents($response['body']);
315+
$this->lastRequest['response']['body'] = $response['body'];
316+
}
314317

315-
if ($response['status'] >= 400 && $response['status'] < 500) {
316-
$ignore = $request['client']['ignore'] ?? [];
317-
// Skip 404 if succeeded true in the body (e.g. clear_scroll)
318-
$body = $response['body'] ?? '';
319-
if (strpos($body, '"succeeded":true') !== false) {
320-
$ignore[] = 404;
318+
if ($response['status'] >= 400 && $response['status'] < 500) {
319+
$ignore = $request['client']['ignore'] ?? [];
320+
// Skip 404 if succeeded true in the body (e.g. clear_scroll)
321+
$body = $response['body'] ?? '';
322+
if (strpos($body, '"succeeded":true') !== false) {
323+
$ignore[] = 404;
324+
}
325+
$this->process4xxError($request, $response, $ignore);
326+
} elseif ($response['status'] >= 500) {
327+
$ignore = $request['client']['ignore'] ?? [];
328+
$this->process5xxError($request, $response, $ignore);
321329
}
322-
$this->process4xxError($request, $response, $ignore);
323-
} elseif ($response['status'] >= 500) {
324-
$ignore = $request['client']['ignore'] ?? [];
325-
$this->process5xxError($request, $response, $ignore);
330+
331+
// No error, deserialize
332+
$response['body'] = $this->serializer->deserialize($response['body'], $response['transfer_stats']);
326333
}
334+
$this->logRequestSuccess($request, $response);
327335

328-
// No error, deserialize
329-
$response['body'] = $this->serializer->deserialize($response['body'], $response['transfer_stats']);
336+
return isset($request['client']['verbose']) && $request['client']['verbose'] === true ? $response : $response['body'];
330337
}
331-
$this->logRequestSuccess($request, $response);
332-
333-
return isset($request['client']['verbose']) && $request['client']['verbose'] === true ? $response : $response['body'];
334-
});
338+
);
335339

336340
return $response;
337341
};
@@ -374,8 +378,8 @@ public function logWarning(array $request, array $response): void
374378
/**
375379
* Log a successful request
376380
*
377-
* @param array $request
378-
* @param array $response
381+
* @param array $request
382+
* @param array $response
379383
* @return void
380384
*/
381385
public function logRequestSuccess(array $request, array $response): void
@@ -412,8 +416,8 @@ public function logRequestSuccess(array $request, array $response): void
412416
/**
413417
* Log a failed request
414418
*
415-
* @param array $request
416-
* @param array $response
419+
* @param array $request
420+
* @param array $response
417421
* @param \Exception $exception
418422
*
419423
* @return void
@@ -571,7 +575,7 @@ protected function getCurlRetryException(array $request, array $response): Elast
571575
* Get the OS version using php_uname if available
572576
* otherwise it returns an empty string
573577
*
574-
* @see https://github.com/elastic/elasticsearch-php/issues/922
578+
* @see https://github.com/elastic/elasticsearch-php/issues/922
575579
*/
576580
private function getOSVersion(): string
577581
{

src/Elasticsearch/Endpoints/AsyncSearch/Delete.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
* Class Delete
2424
* Elasticsearch API name async_search.delete
2525
* Generated running $ php util/GenerateEndpoints.php 7.9
26-
*
2726
*/
2827
class Delete extends AbstractEndpoint
2928
{

src/Elasticsearch/Endpoints/AsyncSearch/Get.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
* Class Get
2424
* Elasticsearch API name async_search.get
2525
* Generated running $ php util/GenerateEndpoints.php 7.9
26-
*
2726
*/
2827
class Get extends AbstractEndpoint
2928
{

src/Elasticsearch/Endpoints/AsyncSearch/Submit.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
* Class Submit
2323
* Elasticsearch API name async_search.submit
2424
* Generated running $ php util/GenerateEndpoints.php 7.9
25-
*
2625
*/
2726
class Submit extends AbstractEndpoint
2827
{

src/Elasticsearch/Endpoints/Autoscaling/DeleteAutoscalingPolicy.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
* Class DeleteAutoscalingPolicy
2424
* Elasticsearch API name autoscaling.delete_autoscaling_policy
2525
* Generated running $ php util/GenerateEndpoints.php 7.9
26-
*
2726
*/
2827
class DeleteAutoscalingPolicy extends AbstractEndpoint
2928
{

0 commit comments

Comments
 (0)