From 24900ef18d196bf820a9a7054553db6b48343639 Mon Sep 17 00:00:00 2001 From: Martin Hujer Date: Tue, 7 Nov 2017 20:31:15 +0100 Subject: [PATCH] [src] add PHP_CodeSniffer (#647) * PSR-2 fixes (auto) * PSR-2 manual exclude * PSR-2 check as a part of build --- composer.json | 1 + src/Elasticsearch/Client.php | 2 +- src/Elasticsearch/ClientBuilder.php | 11 +++-- src/Elasticsearch/Connections/Connection.php | 16 ++++--- .../ConnectionFactoryInterface.php | 9 +++- .../Connections/ConnectionInterface.php | 13 +++++- src/Elasticsearch/Endpoints/FieldCaps.php | 2 +- src/Elasticsearch/Endpoints/Remote/Info.php | 1 + src/Elasticsearch/Endpoints/TermVectors.php | 44 +++++++++---------- .../Namespaces/NamespaceBuilderInterface.php | 3 +- src/Elasticsearch/Transport.php | 7 ++- 11 files changed, 68 insertions(+), 41 deletions(-) diff --git a/composer.json b/composer.json index e44114cbe..7b966a0dd 100644 --- a/composer.json +++ b/composer.json @@ -44,6 +44,7 @@ }, "scripts": { "phpcs": [ + "phpcs --standard=ruleset.xml --extensions=php --encoding=utf-8 --tab-width=4 -sp src", "phpcs --standard=ruleset.xml --extensions=php --encoding=utf-8 --tab-width=4 -sp tests" ], "phpstan": [ diff --git a/src/Elasticsearch/Client.php b/src/Elasticsearch/Client.php index cf1ac43a8..a2be325e0 100644 --- a/src/Elasticsearch/Client.php +++ b/src/Elasticsearch/Client.php @@ -1564,7 +1564,7 @@ private function verifyNotNullOrEmpty($name, $var) /** * @param $endpoint AbstractEndpoint - * + * * @throws \Exception * @return array */ diff --git a/src/Elasticsearch/ClientBuilder.php b/src/Elasticsearch/ClientBuilder.php index b90548ab4..d26086a2a 100644 --- a/src/Elasticsearch/ClientBuilder.php +++ b/src/Elasticsearch/ClientBuilder.php @@ -558,13 +558,15 @@ private function buildTransport() $connections, $this->selector, $this->connectionFactory, - $this->connectionPoolArgs); + $this->connectionPoolArgs + ); } elseif (is_null($this->connectionPool)) { $this->connectionPool = new StaticNoPingConnectionPool( $connections, $this->selector, $this->connectionFactory, - $this->connectionPoolArgs); + $this->connectionPoolArgs + ); } if (is_null($this->retries)) { @@ -613,7 +615,7 @@ private function buildConnectionsFromHosts($hosts) if (is_string($host)) { $host = $this->prependMissingScheme($host); $host = $this->extractURIParts($host); - } else if (is_array($host)) { + } elseif (is_array($host)) { $host = $this->normalizeExtendedHost($host); } else { $this->logger->error("Could not parse host: ".print_r($host, true)); @@ -629,7 +631,8 @@ private function buildConnectionsFromHosts($hosts) * @param $host * @return array */ - private function normalizeExtendedHost($host) { + private function normalizeExtendedHost($host) + { if (isset($host['host']) === false) { $this->logger->error("Required 'host' was not defined in extended format: ".print_r($host, true)); throw new RuntimeException("Required 'host' was not defined in extended format: ".print_r($host, true)); diff --git a/src/Elasticsearch/Connections/Connection.php b/src/Elasticsearch/Connections/Connection.php index 782af1fc7..6fe305e80 100644 --- a/src/Elasticsearch/Connections/Connection.php +++ b/src/Elasticsearch/Connections/Connection.php @@ -99,9 +99,15 @@ class Connection implements ConnectionInterface * @param \Psr\Log\LoggerInterface $log Logger object * @param \Psr\Log\LoggerInterface $trace */ - public function __construct($handler, $hostDetails, $connectionParams, - SerializerInterface $serializer, LoggerInterface $log, LoggerInterface $trace) - { + public function __construct( + $handler, + $hostDetails, + $connectionParams, + SerializerInterface $serializer, + LoggerInterface $log, + LoggerInterface $trace + ) { + if (isset($hostDetails['port']) !== true) { $hostDetails['port'] = 9200; } @@ -290,7 +296,6 @@ private function wrapHandler(callable $handler, LoggerInterface $logger, LoggerI ); return isset($request['client']['verbose']) && $request['client']['verbose'] === true ? $response : $response['body']; - }); return $response; @@ -309,7 +314,7 @@ private function getURI($uri, $params) array_walk($params, function (&$value, &$key) { if ($value === true) { $value = 'true'; - } else if ($value === false) { + } elseif ($value === false) { $value = 'false'; } }); @@ -686,7 +691,6 @@ private function tryDeserializeError($response, $errorClass) if (is_array($error) === true) { // 2.0 structured exceptions if (isset($error['error']['reason']) === true) { - // Try to use root cause first (only grabs the first root cause) $root = $error['error']['root_cause']; if (isset($root) && isset($root[0])) { diff --git a/src/Elasticsearch/Connections/ConnectionFactoryInterface.php b/src/Elasticsearch/Connections/ConnectionFactoryInterface.php index 242a32105..94b628a71 100644 --- a/src/Elasticsearch/Connections/ConnectionFactoryInterface.php +++ b/src/Elasticsearch/Connections/ConnectionFactoryInterface.php @@ -23,8 +23,13 @@ interface ConnectionFactoryInterface * @param LoggerInterface $logger * @param LoggerInterface $tracer */ - public function __construct(callable $handler, array $connectionParams, - SerializerInterface $serializer, LoggerInterface $logger, LoggerInterface $tracer); + public function __construct( + callable $handler, + array $connectionParams, + SerializerInterface $serializer, + LoggerInterface $logger, + LoggerInterface $tracer + ); /** * @param $hostDetails diff --git a/src/Elasticsearch/Connections/ConnectionInterface.php b/src/Elasticsearch/Connections/ConnectionInterface.php index 44495dbdc..8f675b246 100644 --- a/src/Elasticsearch/Connections/ConnectionInterface.php +++ b/src/Elasticsearch/Connections/ConnectionInterface.php @@ -27,8 +27,14 @@ interface ConnectionInterface * @param \Psr\Log\LoggerInterface $log Logger object * @param \Psr\Log\LoggerInterface $trace Logger object */ - public function __construct($handler, $hostDetails, $connectionParams, - SerializerInterface $serializer, LoggerInterface $log, LoggerInterface $trace); + public function __construct( + $handler, + $hostDetails, + $connectionParams, + SerializerInterface $serializer, + LoggerInterface $log, + LoggerInterface $trace + ); /** * Get the transport schema for this connection @@ -95,5 +101,8 @@ public function getLastRequestInfo(); * @param \Elasticsearch\Transport $transport * @return mixed */ + // @codingStandardsIgnoreStart + // "Arguments with default values must be at the end of the argument list" - cannot change the interface public function performRequest($method, $uri, $params = null, $body = null, $options = [], Transport $transport); + // @codingStandardsIgnoreEnd } diff --git a/src/Elasticsearch/Endpoints/FieldCaps.php b/src/Elasticsearch/Endpoints/FieldCaps.php index 33e53bc24..7e821283c 100644 --- a/src/Elasticsearch/Endpoints/FieldCaps.php +++ b/src/Elasticsearch/Endpoints/FieldCaps.php @@ -39,7 +39,7 @@ public function getURI() { $index = $this->index; - if (isset($index) === true ) { + if (isset($index) === true) { return "/$index/_field_caps"; } else { return "/_field_caps"; diff --git a/src/Elasticsearch/Endpoints/Remote/Info.php b/src/Elasticsearch/Endpoints/Remote/Info.php index b4e8be300..154c2de28 100644 --- a/src/Elasticsearch/Endpoints/Remote/Info.php +++ b/src/Elasticsearch/Endpoints/Remote/Info.php @@ -1,6 +1,7 @@ index) !== true) { - throw new Exceptions\RuntimeException( - 'index is required for TermVectors' - ); - } - if (isset($this->type) !== true) { - throw new Exceptions\RuntimeException( - 'type is required for TermVectors' - ); - } - if (isset($this->id) !== true && isset($this->body['doc']) !== true) { - throw new Exceptions\RuntimeException( - 'id or doc is required for TermVectors' - ); - } + throw new Exceptions\RuntimeException( + 'index is required for TermVectors' + ); + } + if (isset($this->type) !== true) { + throw new Exceptions\RuntimeException( + 'type is required for TermVectors' + ); + } + if (isset($this->id) !== true && isset($this->body['doc']) !== true) { + throw new Exceptions\RuntimeException( + 'id or doc is required for TermVectors' + ); + } - $index = $this->index; - $type = $this->type; - $id = $this->id; - $uri = "/$index/$type/_termvectors"; + $index = $this->index; + $type = $this->type; + $id = $this->id; + $uri = "/$index/$type/_termvectors"; - if ($id !== null) { - $uri = "/$index/$type/$id/_termvectors"; - } + if ($id !== null) { + $uri = "/$index/$type/$id/_termvectors"; + } - return $uri; + return $uri; } /** diff --git a/src/Elasticsearch/Namespaces/NamespaceBuilderInterface.php b/src/Elasticsearch/Namespaces/NamespaceBuilderInterface.php index 7171dbbca..b2fd0741e 100644 --- a/src/Elasticsearch/Namespaces/NamespaceBuilderInterface.php +++ b/src/Elasticsearch/Namespaces/NamespaceBuilderInterface.php @@ -11,7 +11,6 @@ namespace Elasticsearch\Namespaces; - use Elasticsearch\Serializers\SerializerInterface; use Elasticsearch\Transport; @@ -34,4 +33,4 @@ public function getName(); * @return Object */ public function getObject(Transport $transport, SerializerInterface $serializer); -} \ No newline at end of file +} diff --git a/src/Elasticsearch/Transport.php b/src/Elasticsearch/Transport.php index 4436f3e7f..bd7782aa8 100644 --- a/src/Elasticsearch/Transport.php +++ b/src/Elasticsearch/Transport.php @@ -48,8 +48,12 @@ class Transport * @param ConnectionPool\AbstractConnectionPool $connectionPool * @param \Psr\Log\LoggerInterface $log Monolog logger object */ + // @codingStandardsIgnoreStart + // "Arguments with default values must be at the end of the argument list" - cannot change the interface public function __construct($retries, $sniffOnStart = false, AbstractConnectionPool $connectionPool, LoggerInterface $log) { + // @codingStandardsIgnoreEnd + $this->log = $log; $this->connectionPool = $connectionPool; $this->retries = $retries; @@ -119,7 +123,8 @@ function ($response) { // Otherwise schedule a check $this->connectionPool->scheduleCheck(); } - }); + } + ); return $future; }