Skip to content

Commit

Permalink
Automated PSR-2 style cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
polyfractal committed May 9, 2016
1 parent 8238cb3 commit fbe6f92
Show file tree
Hide file tree
Showing 20 changed files with 54 additions and 47 deletions.
6 changes: 6 additions & 0 deletions .php_cs
Expand Up @@ -5,6 +5,12 @@ function php_cs() {
->exclude('benchmarks')
->exclude('docs')
->exclude('util')
->exclude('.github')
->exclude('util')
->exclude('travis')
->exclude('util/cache')
->exclude('util/elasticsearch')
->exclude('vendor')
->in(__DIR__);

return Symfony\CS\Config\Config::create()
Expand Down
3 changes: 2 additions & 1 deletion src/Elasticsearch/Client.php
Expand Up @@ -1441,7 +1441,8 @@ public function extractArgument(&$params, $arg)
}
}

private function verifyNotNullOrEmpty($name, $var) {
private function verifyNotNullOrEmpty($name, $var)
{
if ($var === null) {
throw new InvalidArgumentException("$name cannot be null.");
}
Expand Down
3 changes: 2 additions & 1 deletion src/Elasticsearch/ClientBuilder.php
Expand Up @@ -106,7 +106,8 @@ public static function create()
* @throws Common\Exceptions\RuntimeException
* @return \Elasticsearch\Client
*/
public static function fromConfig($config, $quiet = false) {
public static function fromConfig($config, $quiet = false)
{
$builder = new self;
foreach ($config as $key => $value) {
$method = "set$key";
Expand Down
1 change: 0 additions & 1 deletion src/Elasticsearch/ConnectionPool/SimpleConnectionPool.php
Expand Up @@ -32,5 +32,4 @@ public function nextConnection($force = false)
public function scheduleCheck()
{
}

}
14 changes: 7 additions & 7 deletions src/Elasticsearch/Connections/Connection.php
Expand Up @@ -187,7 +187,6 @@ private function wrapHandler(callable $handler, LoggerInterface $logger, LoggerI

if (isset($response['error']) === true) {
if ($response['error'] instanceof ConnectException || $response['error'] instanceof RingException) {

$this->log->warning("Curl exception encountered.");

$exception = $this->getCurlRetryException($request, $response);
Expand Down Expand Up @@ -566,7 +565,7 @@ private function process4xxError($request, $response, $ignore)
$exception = new Conflict409Exception($responseBody, $statusCode);
} elseif ($statusCode === 400 && strpos($responseBody, 'script_lang not supported') !== false) {
$exception = new ScriptLangNotSupportedException($responseBody. $statusCode);
} elseif ($statusCode === 408 ) {
} elseif ($statusCode === 408) {
$exception = new RequestTimeout408Exception($responseBody, $statusCode);
}

Expand Down Expand Up @@ -628,15 +627,18 @@ private function process5xxError($request, $response, $ignore)
throw $exception;
}

private function tryDeserialize400Error($response) {
private function tryDeserialize400Error($response)
{
return $this->tryDeserializeError($response, 'Elasticsearch\Common\Exceptions\BadRequest400Exception');
}

private function tryDeserialize500Error($response) {
private function tryDeserialize500Error($response)
{
return $this->tryDeserializeError($response, 'Elasticsearch\Common\Exceptions\ServerErrorResponseException');
}

private function tryDeserializeError($response, $errorClass) {
private function tryDeserializeError($response, $errorClass)
{
$error = $this->serializer->deserialize($response['body'], $response['transfer_stats']);
if (is_array($error) === true) {
// 2.0 structured exceptions
Expand All @@ -655,7 +657,6 @@ private function tryDeserializeError($response, $errorClass) {
$original = new $errorClass($response['body'], $response['status']);

return new $errorClass("$type: $cause", $response['status'], $original);

} elseif (isset($error['error']) === true) {
// <2.0 semi-structured exceptions
$original = new $errorClass($response['body'], $response['status']);
Expand All @@ -666,7 +667,6 @@ private function tryDeserializeError($response, $errorClass) {
// <2.0 "i just blew up" nonstructured exception
// $error is an array but we don't know the format, reuse the response body instead
return new $errorClass($response['body'], $response['status']);

}

// <2.0 "i just blew up" nonstructured exception
Expand Down
2 changes: 1 addition & 1 deletion src/Elasticsearch/Endpoints/Cat/Segments.php
Expand Up @@ -58,4 +58,4 @@ protected function getMethod()
{
return 'GET';
}
}
}
3 changes: 2 additions & 1 deletion src/Elasticsearch/Endpoints/Indices/Flush.php
Expand Up @@ -17,7 +17,8 @@ class Flush extends AbstractEndpoint
{
protected $synced = false;

public function setSynced($synced) {
public function setSynced($synced)
{
$this->synced = $synced;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Elasticsearch/Endpoints/Indices/ShardStores.php
Expand Up @@ -56,4 +56,4 @@ protected function getMethod()
{
return 'GET';
}
}
}
2 changes: 1 addition & 1 deletion src/Elasticsearch/Endpoints/Indices/Upgrade/Get.php
Expand Up @@ -62,4 +62,4 @@ protected function getMethod()
{
return 'GET';
}
}
}
2 changes: 1 addition & 1 deletion src/Elasticsearch/Endpoints/Indices/Upgrade/Post.php
Expand Up @@ -62,4 +62,4 @@ protected function getMethod()
{
return 'POST';
}
}
}
2 changes: 1 addition & 1 deletion src/Elasticsearch/Endpoints/Reindex.php
Expand Up @@ -60,4 +60,4 @@ public function setBody($body)

return $this;
}
}
}
2 changes: 1 addition & 1 deletion src/Elasticsearch/Endpoints/RenderSearchTemplate.php
Expand Up @@ -74,4 +74,4 @@ protected function getMethod()
{
return 'GET';
}
}
}
12 changes: 6 additions & 6 deletions src/Elasticsearch/Helper/Iterators/SearchHitIterator.php
Expand Up @@ -14,12 +14,13 @@
* @link http://elastic.co
* @see Iterator
*/
class SearchHitIterator implements Iterator, \Countable {
class SearchHitIterator implements Iterator, \Countable
{

/**
* @var SearchResponseIterator
*/
private $search_responses;
private $search_responses;

/**
* @var int
Expand Down Expand Up @@ -64,7 +65,7 @@ public function rewind()

// The first page may be empty. In that case, the next page is fetched.
$current_page = $this->search_responses->current();
if($this->search_responses->valid() && empty($current_page['hits']['hits'])) {
if ($this->search_responses->valid() && empty($current_page['hits']['hits'])) {
$this->search_responses->next();
}

Expand All @@ -89,7 +90,7 @@ public function next()
$this->current_key++;
$this->current_hit_index++;
$current_page = $this->search_responses->current();
if(isset($current_page['hits']['hits'][$this->current_hit_index])) {
if (isset($current_page['hits']['hits'][$this->current_hit_index])) {
$this->current_hit_data = $current_page['hits']['hits'][$this->current_hit_index];
} else {
$this->search_responses->next();
Expand Down Expand Up @@ -137,14 +138,13 @@ public function key()
*/
private function readPageData()
{
if($this->search_responses->valid()) {
if ($this->search_responses->valid()) {
$current_page = $this->search_responses->current();
$this->current_hit_index = 0;
$this->current_hit_data = $current_page['hits']['hits'][$this->current_hit_index];
} else {
$this->current_hit_data = null;
}

}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/Elasticsearch/Helper/Iterators/SearchResponseIterator.php
Expand Up @@ -15,7 +15,8 @@
* @link http://elastic.co
* @see Iterator
*/
class SearchResponseIterator implements Iterator {
class SearchResponseIterator implements Iterator
{

/**
* @var Client
Expand Down Expand Up @@ -67,7 +68,8 @@ public function __construct(Client $client, array $search_params)
/**
* Destructor
*/
public function __destruct() {
public function __destruct()
{
$this->clearScroll();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Elasticsearch/Namespaces/IngestNamespace.php
@@ -1,6 +1,7 @@
<?php

namespace Elasticsearch\Namespaces;

use Elasticsearch\Endpoints\Ingest\Pipeline\Delete;
use Elasticsearch\Endpoints\Ingest\Pipeline\Get;
use Elasticsearch\Endpoints\Ingest\Pipeline\Put;
Expand Down Expand Up @@ -114,5 +115,4 @@ public function simulate($params = array())

return $endpoint->resultOrFuture($response);
}

}
4 changes: 1 addition & 3 deletions src/Elasticsearch/Namespaces/TasksNamespace.php
@@ -1,10 +1,10 @@
<?php

namespace Elasticsearch\Namespaces;

use Elasticsearch\Endpoints\Tasks\Cancel;
use Elasticsearch\Endpoints\Tasks\Get;


/**
* Class TasksNamespace
*
Expand Down Expand Up @@ -70,6 +70,4 @@ public function cancel($params = array())

return $endpoint->resultOrFuture($response);
}


}
6 changes: 2 additions & 4 deletions tests/Elasticsearch/Tests/ClientTest.php
Expand Up @@ -168,7 +168,7 @@ public function testArrayOfEmptyStringDelete()

try {
$client->delete([
'index' => ['','',''],
'index' => ['', '', ''],
'type' => 'test',
'id' => 'test'
]);
Expand All @@ -180,7 +180,7 @@ public function testArrayOfEmptyStringDelete()
try {
$client->delete([
'index' => 'test',
'type' => ['','',''],
'type' => ['', '', ''],
'id' => 'test'
]);
$this->fail("InvalidArgumentException was not thrown");
Expand Down Expand Up @@ -266,6 +266,4 @@ public function testMaxRetriesException()
throw $e;
}
}


}
Expand Up @@ -210,7 +210,8 @@ public function testAllExceptLastHostFailPingRevivesPreSkip()
$this->assertEquals($goodConnection, $ret);
}

public function testCustomConnectionPoolIT() {
public function testCustomConnectionPoolIT()
{
$clientBuilder = \Elasticsearch\ClientBuilder::create();
$clientBuilder->setHosts(['localhost:1']);
$client = $clientBuilder
Expand Down
Expand Up @@ -15,12 +15,13 @@
class SearchResponseIteratorTest extends \PHPUnit_Framework_TestCase
{

public function tearDown() {
public function tearDown()
{
m::close();
}

public function testWithNoResults() {

public function testWithNoResults()
{
$search_params = array(
'search_type' => 'scan',
'scroll' => '5m',
Expand Down Expand Up @@ -77,7 +78,7 @@ public function testWithNoResults() {

$responses = new SearchResponseIterator($mock_client, $search_params);

foreach($responses as $i => $response) {
foreach ($responses as $i => $response) {
}

$this->assertEquals(0, $i);
Expand Down Expand Up @@ -178,10 +179,9 @@ public function testWithScan()

$responses = new SearchResponseIterator($mock_client, $search_params);

foreach($responses as $i => $response) {
foreach ($responses as $i => $response) {
}

$this->assertEquals(2, $i);
}

}
14 changes: 7 additions & 7 deletions tests/Elasticsearch/Tests/YamlRunnerTest.php
Expand Up @@ -359,7 +359,7 @@ public function testFutureModeYaml()
}
}

static function replaceWithStash($values, $stash)
public static function replaceWithStash($values, $stash)
{
if (count($stash) === 0) {
return $values;
Expand All @@ -372,7 +372,6 @@ static function replaceWithStash($values, $stash)
$item = $stash[$item];
}
} elseif (is_object($item) === true) {

$tItem = json_decode(json_encode($item), true);

// Have to make sure we don't convert empty objects ( {} ) into arrays
Expand Down Expand Up @@ -488,7 +487,6 @@ private function executeTestCase($test, $testFile, $future)
if (empty($settings) === true) {
$response = YamlRunnerTest::replaceWithStash($response, $stash);
$this->assertTruthy($response, $settings);

} else {
$settings = YamlRunnerTest::replaceWithStash($settings, $stash);
echo "settings after replace: ";
Expand Down Expand Up @@ -519,7 +517,6 @@ private function executeTestCase($test, $testFile, $future)
print_r($stash);
echo "\n";
ob_flush();

} elseif ($operator === "length") {
$expectedCount = $this->getValue($settings, key($settings));
$this->assertCount($expectedCount, $this->getNestedVar($response, key($settings)));
Expand Down Expand Up @@ -578,7 +575,8 @@ private function executeTestCase($test, $testFile, $future)
}
}

private function handleCaughtException(\Exception $exception, $expectedError) {
private function handleCaughtException(\Exception $exception, $expectedError)
{
$reflect = new ReflectionClass($exception);
$caught = $reflect->getShortName();
$passed = false;
Expand Down Expand Up @@ -627,7 +625,8 @@ private function handleCaughtException(\Exception $exception, $expectedError) {
}


private static function checkExceptionRegex($expectedError, \Exception $exception) {
private static function checkExceptionRegex($expectedError, \Exception $exception)
{
return isset($expectedError) === true && preg_match("/$expectedError/", $exception->getMessage()) === 1;
}

Expand Down Expand Up @@ -728,7 +727,8 @@ private function checkForTimestamp($file, $document)
* @param $file
* @return mixed
*/
private function checkForList($document) {
private function checkForList($document)
{
return str_replace("tasks.list", "tasks.get", $document);
}

Expand Down

0 comments on commit fbe6f92

Please sign in to comment.