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 vendor"
+                       "parallel-lint . --exclude vendor",
+                       "phpcs -p -s"
                ]
        }
 }
diff --git a/phpcs.xml b/phpcs.xml
new file mode 100644
index 0000000..ede6c5d
--- /dev/null
+++ b/phpcs.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ruleset>
+       <rule ref="vendor/mediawiki/mediawiki-codesniffer/MediaWiki"/>
+       <file>.</file>
+       <arg name="extensions" value="php,php5,inc"/>
+       <arg name="encoding" value="utf8"/>
+       <exclude-pattern>vendor</exclude-pattern>
+       <exclude-pattern>node_modules</exclude-pattern>
+</ruleset>
diff --git a/tests/phpunit/UtilTest.php b/tests/phpunit/UtilTest.php
index 8729b92..0c643bd 100644
--- a/tests/phpunit/UtilTest.php
+++ b/tests/phpunit/UtilTest.php
@@ -22,27 +22,29 @@
  */
 
 class UtilTest extends MediaWikiTestCase {
-        public function testBackoffDelay() {
-                for ( $i = 0; $i < 100; $i++ ) {
-                        $this->assertLessThanOrEqual( 16, 
MWElasticUtils::backoffDelay( 1 ) );
-                        $this->assertLessThanOrEqual( 256, 
MWElasticUtils::backoffDelay( 5 ) );
-                }
-        }
+       public function testBackoffDelay() {
+               for ( $i = 0; $i < 100; $i++ ) {
+                       $this->assertLessThanOrEqual( 16, 
MWElasticUtils::backoffDelay( 1 ) );
+                       $this->assertLessThanOrEqual( 256, 
MWElasticUtils::backoffDelay( 5 ) );
+               }
+       }
 
-        public function testWithRetry() {
-                $calls = 0;
-                $func = function() use ( &$calls ) {
-                        $calls++;
-                        if( $calls <= 5 ) {
-                                throw new InvalidException();
-                        }
-                };
-                $errorCallbackCalls = 0;
-                MWElasticUtils::withRetry( 5, $func, function ($e, $errCount) 
use ( &$errorCallbackCalls ) {
-                        $errorCallbackCalls++;
-                        $this->assertEquals( 
"Elastica\Exception\InvalidException", get_class( $e ) );
-                } );
-                $this->assertEquals( 6, $calls );
-                $this->assertEquals( 5, $errorCallbackCalls );
-        }
+       public function testWithRetry() {
+               $calls = 0;
+               $func = function() use ( &$calls ) {
+                       $calls++;
+                       if ( $calls <= 5 ) {
+                               throw new InvalidException();
+                       }
+               };
+               $errorCallbackCalls = 0;
+               MWElasticUtils::withRetry( 5, $func,
+                       function( $e, $errCount ) use ( &$errorCallbackCalls ) {
+                               $errorCallbackCalls++;
+                               $this->assertEquals( 
"Elastica\Exception\InvalidException", get_class( $e ) );
+                       }
+               );
+               $this->assertEquals( 6, $calls );
+               $this->assertEquals( 5, $errorCallbackCalls );
+       }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/354254
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I8959022e4b439d79ff153c39b82b58c51a964114
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Elastica
Gerrit-Branch: master
Gerrit-Owner: Umherirrender <umherirrender_de...@web.de>
Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to