Skip to content

Commit

Permalink
[src] add PHP_CodeSniffer (#647)
Browse files Browse the repository at this point in the history
* PSR-2 fixes (auto)

* PSR-2 manual exclude

* PSR-2 check as a part of build
  • Loading branch information
mhujer authored and polyfractal committed Nov 14, 2017
1 parent 088a509 commit 24900ef
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 41 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
2 changes: 1 addition & 1 deletion src/Elasticsearch/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -1564,7 +1564,7 @@ private function verifyNotNullOrEmpty($name, $var)

/**
* @param $endpoint AbstractEndpoint
*
*
* @throws \Exception
* @return array
*/
Expand Down
11 changes: 7 additions & 4 deletions src/Elasticsearch/ClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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));
Expand All @@ -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));
Expand Down
16 changes: 10 additions & 6 deletions src/Elasticsearch/Connections/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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';
}
});
Expand Down Expand Up @@ -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])) {
Expand Down
9 changes: 7 additions & 2 deletions src/Elasticsearch/Connections/ConnectionFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions src/Elasticsearch/Connections/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion src/Elasticsearch/Endpoints/FieldCaps.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
1 change: 1 addition & 0 deletions src/Elasticsearch/Endpoints/Remote/Info.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

namespace Elasticsearch\Endpoints\Remote;

use Elasticsearch\Endpoints\AbstractEndpoint;

/**
Expand Down
44 changes: 22 additions & 22 deletions src/Elasticsearch/Endpoints/TermVectors.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,31 @@ public function setBody($body)
public function getURI()
{
if (isset($this->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;
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Elasticsearch/Namespaces/NamespaceBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Elasticsearch\Namespaces;


use Elasticsearch\Serializers\SerializerInterface;
use Elasticsearch\Transport;

Expand All @@ -34,4 +33,4 @@ public function getName();
* @return Object
*/
public function getObject(Transport $transport, SerializerInterface $serializer);
}
}
7 changes: 6 additions & 1 deletion src/Elasticsearch/Transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -119,7 +123,8 @@ function ($response) {
// Otherwise schedule a check
$this->connectionPool->scheduleCheck();
}
});
}
);

return $future;
}
Expand Down

0 comments on commit 24900ef

Please sign in to comment.