[MediaWiki-commits] [Gerrit] mediawiki...Elastica[master]: Add phpcs and make pass
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/354254 ) Change subject: Add phpcs and make pass .. Add phpcs and make pass Change-Id: I8959022e4b439d79ff153c39b82b58c51a964114 --- M ElasticaConnection.php M composer.json A phpcs.xml M tests/phpunit/UtilTest.php 4 files changed, 53 insertions(+), 37 deletions(-) Approvals: jenkins-bot: Verified Jforrester: Looks good to me, approved diff --git a/ElasticaConnection.php b/ElasticaConnection.php index 6ef082d..6441808 100644 --- a/ElasticaConnection.php +++ b/ElasticaConnection.php @@ -27,7 +27,7 @@ /** * @return array(string) server ips or hostnames */ - public abstract function getServerList(); + abstract public function getServerList(); /** * How many times can we attempt to connect per host? @@ -210,7 +210,6 @@ } } - /** * Utility class */ @@ -226,22 +225,24 @@ * @param int $retryAttempts the number of times we retry * @param callable $retryErrorCallback function called before each retries */ - public static function iterateOverScroll( \Elastica\Index $index, $scrollId, $scrollTime, $consumer, $limit = 0, $retryAttempts = 0, $retryErrorCallback = null ) { + public static function iterateOverScroll( \Elastica\Index $index, $scrollId, $scrollTime, + $consumer, $limit = 0, $retryAttempts = 0, $retryErrorCallback = null + ) { $clearScroll = true; $fetched = 0; - while( true ) { + while ( true ) { $result = static::withRetry( $retryAttempts, function() use ( $index, $scrollId, $scrollTime ) { - return $index->search ( array(), array( + return $index->search( [], [ 'scroll_id' => $scrollId, 'scroll' => $scrollTime - ) ); + ] ); }, $retryErrorCallback ); $scrollId = $result->getResponse()->getScrollId(); - if( !$result->count() ) { + if ( !$result->count() ) { // No need to clear scroll on the last call $clearScroll = false; break; @@ -250,21 +251,22 @@ $fetched += $result->count(); $results = $result->getResults(); - if( $limit > 0 && $fetched > $limit ) { - $results = array_slice( $results, 0, sizeof( $results ) - ( $fetched - $limit ) ); + if ( $limit > 0 && $fetched > $limit ) { + $results = array_slice( $results, 0, count( $results ) - ( $fetched - $limit ) ); } $consumer( $results ); - if( $limit > 0 && $fetched >= $limit ) { + if ( $limit > 0 && $fetched >= $limit ) { break; } } // @todo: catch errors and clear the scroll, it'd be easy with a finally block ... - if( $clearScroll ) { + if ( $clearScroll ) { try { $index->getClient()->request( "_search/scroll/".$scrollId, \Elastica\Request::DELETE ); - } catch ( Exception $e ) {} + } catch ( Exception $e ) { + } } } @@ -289,7 +291,7 @@ return $func(); } catch ( Exception $e ) { $errors += 1; - if( $beforeRetry ) { + if ( $beforeRetry ) { $beforeRetry( $e, $errors ); } else { $seconds = static::backoffDelay( $errors ); diff --git a/composer.json b/composer.json index 3216fe9..c83e077 100644 --- a/composer.json +++ b/composer.json @@ -43,11 +43,14 @@ }, "require-dev": { "jakub-onderka/php-parallel-lint": "0.9.2", - "jakub-onderka/php-console-highlighter": "0.3.2" + "jakub-onderka/php-console-highlighter": "0.3.2", + "mediawiki/mediawiki-codesniffer": "0.7.2" }, "scripts": { + "fix": "phpcbf", "test": [ - "parallel-lint . --exclude
[MediaWiki-commits] [Gerrit] mediawiki...Elastica[master]: Add phpcs and make pass
Umherirrender has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/354254 ) Change subject: Add phpcs and make pass .. Add phpcs and make pass Change-Id: I8959022e4b439d79ff153c39b82b58c51a964114 --- M ElasticaConnection.php M composer.json A phpcs.xml M tests/phpunit/UtilTest.php 4 files changed, 53 insertions(+), 37 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Elastica refs/changes/54/354254/1 diff --git a/ElasticaConnection.php b/ElasticaConnection.php index 6ef082d..6441808 100644 --- a/ElasticaConnection.php +++ b/ElasticaConnection.php @@ -27,7 +27,7 @@ /** * @return array(string) server ips or hostnames */ - public abstract function getServerList(); + abstract public function getServerList(); /** * How many times can we attempt to connect per host? @@ -210,7 +210,6 @@ } } - /** * Utility class */ @@ -226,22 +225,24 @@ * @param int $retryAttempts the number of times we retry * @param callable $retryErrorCallback function called before each retries */ - public static function iterateOverScroll( \Elastica\Index $index, $scrollId, $scrollTime, $consumer, $limit = 0, $retryAttempts = 0, $retryErrorCallback = null ) { + public static function iterateOverScroll( \Elastica\Index $index, $scrollId, $scrollTime, + $consumer, $limit = 0, $retryAttempts = 0, $retryErrorCallback = null + ) { $clearScroll = true; $fetched = 0; - while( true ) { + while ( true ) { $result = static::withRetry( $retryAttempts, function() use ( $index, $scrollId, $scrollTime ) { - return $index->search ( array(), array( + return $index->search( [], [ 'scroll_id' => $scrollId, 'scroll' => $scrollTime - ) ); + ] ); }, $retryErrorCallback ); $scrollId = $result->getResponse()->getScrollId(); - if( !$result->count() ) { + if ( !$result->count() ) { // No need to clear scroll on the last call $clearScroll = false; break; @@ -250,21 +251,22 @@ $fetched += $result->count(); $results = $result->getResults(); - if( $limit > 0 && $fetched > $limit ) { - $results = array_slice( $results, 0, sizeof( $results ) - ( $fetched - $limit ) ); + if ( $limit > 0 && $fetched > $limit ) { + $results = array_slice( $results, 0, count( $results ) - ( $fetched - $limit ) ); } $consumer( $results ); - if( $limit > 0 && $fetched >= $limit ) { + if ( $limit > 0 && $fetched >= $limit ) { break; } } // @todo: catch errors and clear the scroll, it'd be easy with a finally block ... - if( $clearScroll ) { + if ( $clearScroll ) { try { $index->getClient()->request( "_search/scroll/".$scrollId, \Elastica\Request::DELETE ); - } catch ( Exception $e ) {} + } catch ( Exception $e ) { + } } } @@ -289,7 +291,7 @@ return $func(); } catch ( Exception $e ) { $errors += 1; - if( $beforeRetry ) { + if ( $beforeRetry ) { $beforeRetry( $e, $errors ); } else { $seconds = static::backoffDelay( $errors ); diff --git a/composer.json b/composer.json index 3216fe9..c83e077 100644 --- a/composer.json +++ b/composer.json @@ -43,11 +43,14 @@ }, "require-dev": { "jakub-onderka/php-parallel-lint": "0.9.2", - "jakub-onderka/php-console-highlighter": "0.3.2" + "jakub-onderka/php-console-highlighter": "0.3.2", + "mediawiki/mediawiki-codesniffer": "0.7.2" }, "scripts": { + "fix": "phpcbf", "test": [ -