Anomie has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/312285

Change subject: Add phpcs testing
......................................................................

Add phpcs testing

And fix errors. But ignore the htmlform subdirectory because that's
going away real soon now.

Change-Id: I1fa1372c43627645bfbd9cb1b35f7998ae2e1c20
---
M ApiFeatureUsage.php
M ApiFeatureUsageQueryEngineElastica.php
M ApiQueryFeatureUsage.php
M SpecialApiFeatureUsage.php
M composer.json
M extension.json
A phpcs.xml
7 files changed, 78 insertions(+), 60 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ApiFeatureUsage 
refs/changes/85/312285/1

diff --git a/ApiFeatureUsage.php b/ApiFeatureUsage.php
index 8e004cd..f4aea03 100644
--- a/ApiFeatureUsage.php
+++ b/ApiFeatureUsage.php
@@ -27,7 +27,8 @@
        $wgMessagesDirs['ApiFeatureUsage'] = __DIR__ . '/i18n';
        $wgExtensionMessagesFiles['ApiFeatureUsageAlias'] = __DIR__ . 
'/ApiFeatureUsage.alias.php';
        /* wfWarn(
-               'Deprecated PHP entry point used for ApiFeatureUsage extension. 
Please use wfLoadExtension instead, ' .
+               'Deprecated PHP entry point used for ApiFeatureUsage extension. 
' .
+               'Please use wfLoadExtension instead, ' .
                'see https://www.mediawiki.org/wiki/Extension_registration for 
more details.'
        ); */
        return;
diff --git a/ApiFeatureUsageQueryEngineElastica.php 
b/ApiFeatureUsageQueryEngineElastica.php
index f34e77f..424d3e0 100644
--- a/ApiFeatureUsageQueryEngineElastica.php
+++ b/ApiFeatureUsageQueryEngineElastica.php
@@ -17,14 +17,14 @@
        private $indexNames = null;
 
        public function __construct( array $options ) {
-               $options += array(
+               $options += [
                        'indexPrefix' => 'apifeatureusage-',
                        'indexFormat' => 'Y.m.d',
                        'type' => 'api-feature-usage-sanitized',
                        'featureField' => 'feature',
                        'timestampField' => '@timestamp',
                        'agentField' => 'agent',
-               );
+               ];
 
                parent::__construct( $options );
        }
@@ -45,7 +45,7 @@
        }
 
        public function execute( $agent, MWTimestamp $start, MWTimestamp $end ) 
{
-               $status = Status::newGood( array() );
+               $status = Status::newGood( [] );
 
                # Force $start and $end to day boundaries
                $oneday = new DateInterval( 'P1D' );
@@ -65,10 +65,10 @@
                $prefix->setPrefix( $this->options['agentField'], $agent );
                $bools->addMust( $prefix );
 
-               $bools->addMust( new Elastica\Query\Range( 
$this->options['timestampField'], array(
+               $bools->addMust( new Elastica\Query\Range( 
$this->options['timestampField'], [
                        'gte' => $start->getTimestamp( TS_ISO_8601 ),
                        'lte' => $end->getTimestamp( TS_ISO_8601 ),
-               ) ) );
+               ] ) );
                $query->setQuery( $bools );
 
                $termsAgg = new Elastica\Aggregation\Terms( 'feature' );
@@ -89,7 +89,7 @@
                );
 
                $allIndexes = $this->getIndexNames();
-               $indexes = array();
+               $indexes = [];
                $skippedAny = false;
                $s = clone $start->timestamp;
                while ( $s <= $end->timestamp ) {
@@ -121,16 +121,16 @@
                        );
                }
 
-               $ret = array();
+               $ret = [];
                $aggs = $res->getAggregations();
                if ( isset( $aggs['feature'] ) ) {
                        foreach ( $aggs['feature']['buckets'] as $feature ) {
                                foreach ( $feature['date']['buckets'] as $date 
) {
-                                       $ret[] = array(
+                                       $ret[] = [
                                                'feature' => $feature['key'],
                                                'date' => 
$date['key_as_string'],
                                                'count' => $date['doc_count'],
-                                       );
+                                       ];
                                }
                        }
                }
@@ -153,7 +153,7 @@
                        $index = $this->options['indexPrefix'] . 
$start->format( $this->options['indexFormat'] );
                        if ( !in_array( $index, $allIndexes ) ) {
                                $start->timestamp->add( $oneday );
-                               return array( $start, $end );
+                               return [ $start, $end ];
                        }
                }
        }
@@ -163,20 +163,20 @@
  * Class to create the connection
  */
 class ApiFeatureUsageQueryEngineElasticaConnection extends ElasticaConnection {
-       private $options = array();
+       private $options = [];
 
        public function __construct( $options = null ) {
                if ( !is_array( $options ) ) {
-                       $options = array();
+                       $options = [];
                }
 
                if ( empty( $options['serverList'] ) || !is_array( 
$options['serverList'] ) ) {
                        throw new MWException( __METHOD__ . ': serverList is 
not set or is not valid.' );
                }
 
-               $this->options = $options + array(
+               $this->options = $options + [
                        'maxConnectionAttempts' => 1,
-               );
+               ];
        }
 
        public function getServerList() {
diff --git a/ApiQueryFeatureUsage.php b/ApiQueryFeatureUsage.php
index cc37966..607e26a 100644
--- a/ApiQueryFeatureUsage.php
+++ b/ApiQueryFeatureUsage.php
@@ -44,40 +44,40 @@
                        $this->setWarning( $warning->inLanguage( 'en' 
)->useDatabase( false )->plain() );
                }
 
-               $r = array(
+               $r = [
                        'agent' => $agent,
                        'start' => $start->getTimestamp( TS_ISO_8601 ),
                        'end' => $end->getTimestamp( TS_ISO_8601 ),
                        'usage' => $status->value,
-               );
+               ];
 
                $this->getResult()->setIndexedTagName( $r['usage'], 'v' );
                $this->getResult()->addValue( 'query', $this->getModuleName(), 
$r );
        }
 
        public function getAllowedParams() {
-               return array(
-                       'start' => array(
+               return [
+                       'start' => [
                                ApiBase::PARAM_TYPE => 'timestamp',
-                       ),
-                       'end' => array(
+                       ],
+                       'end' => [
                                ApiBase::PARAM_TYPE => 'timestamp',
-                       ),
-                       'agent' => array(
+                       ],
+                       'agent' => [
                                ApiBase::PARAM_TYPE => 'string',
-                       ),
-                       'features' => array(
+                       ],
+                       'features' => [
                                ApiBase::PARAM_TYPE => 'string',
                                ApiBase::PARAM_ISMULTI => true,
-                       ),
-               );
+                       ],
+               ];
        }
 
        protected function getExamplesMessages() {
-               return array(
+               return [
                        'action=query&meta=featureusage'
                                => 'apihelp-query+featureusage-example-simple',
-               );
+               ];
        }
 
        public function getHelpUrls() {
diff --git a/SpecialApiFeatureUsage.php b/SpecialApiFeatureUsage.php
index c6aa923..26a90c3 100644
--- a/SpecialApiFeatureUsage.php
+++ b/SpecialApiFeatureUsage.php
@@ -12,7 +12,9 @@
 
                /** @todo These should be migrated to core, once the jquery.ui
                 * objectors write their own date picker. */
-               if ( !isset( HTMLForm::$typeMappings['date'] ) || !isset( 
HTMLForm::$typeMappings['daterange'] ) ) {
+               if ( !isset( HTMLForm::$typeMappings['date'] ) ||
+                       !isset( HTMLForm::$typeMappings['daterange'] )
+               ) {
                        HTMLForm::$typeMappings['date'] = 
'ApiFeatureUsage_HTMLDateField';
                        HTMLForm::$typeMappings['daterange'] = 
'ApiFeatureUsage_HTMLDateRangeField';
                        $this->getOutput()->addModules( 
'ext.apifeatureusage.htmlform' );
@@ -24,29 +26,29 @@
                $this->engine = ApiFeatureUsageQueryEngine::getEngine( $conf );
                list( $start, $end ) = $this->engine->suggestDateRange();
 
-               $form = new HTMLForm( array(
-                       'agent' => array(
+               $form = new HTMLForm( [
+                       'agent' => [
                                'type' => 'text',
                                'default' => '',
                                'label-message' => 
'apifeatureusage-agent-label',
                                'required' => true,
-                       ),
+                       ],
 
-                       'dates' => array(
+                       'dates' => [
                                'type' => 'daterange',
                                'label-message' => 
'apifeatureusage-dates-label',
                                'layout-message' => 
'apifeatureusage-dates-layout',
                                'absolute' => true,
                                'required' => true,
                                'allow-sameday' => true,
-                               'default' => array(
+                               'default' => [
                                        $start->format( 'Y-m-d' ),
                                        $end->format( 'Y-m-d' ),
-                               ),
-                       ),
-               ), $this->getContext() );
+                               ],
+                       ],
+               ], $this->getContext() );
                $form->setMethod( 'get' );
-               $form->setSubmitCallback( array( $this, 'onSubmit' ) );
+               $form->setSubmitCallback( [ $this, 'onSubmit' ] );
                $form->setWrapperLegend( $this->msg( 'apifeatureusage-legend' ) 
);
                $form->addHeaderText( $this->msg( 'apifeatureusage-text' 
)->parseAsBlock() );
                $form->setSubmitTextMsg( 'apifeatureusage-submit' );
@@ -63,7 +65,7 @@
                        $out = $this->getOutput();
                        $out->addModuleStyles( 'ext.apifeatureusage' );
 
-                       $warnings = array();
+                       $warnings = [];
                        foreach ( $status->getWarningsArray() as $warning ) {
                                if ( !$warning instanceof Message ) {
                                        $key = array_shift( $warning );
@@ -78,40 +80,40 @@
                                        $warnings = $warnings[0];
                                }
                                $out->wrapWikiMsg( "<div 
class='error'>\n$1\n</div>",
-                                       array( 'apifeatureusage-warnings', 
$warnings )
+                                       [ 'apifeatureusage-warnings', $warnings 
]
                                );
                        }
 
                        $lang = $this->getLanguage();
-                       $rows = array();
+                       $rows = [];
                        foreach ( $status->value as $row ) {
-                               $cells = array();
-                               $cells[] = Html::element( 'td', array(), 
$row['feature'] );
-                               $cells[] = Html::rawElement( 'td', array(),
-                                       Html::element( 'time', array(), 
$row['date'] )
+                               $cells = [];
+                               $cells[] = Html::element( 'td', [], 
$row['feature'] );
+                               $cells[] = Html::rawElement( 'td', [],
+                                       Html::element( 'time', [], $row['date'] 
)
                                );
-                               $cells[] = Html::element( 'td', array( 'class' 
=> 'mw-apifeatureusage-count' ),
+                               $cells[] = Html::element( 'td', [ 'class' => 
'mw-apifeatureusage-count' ],
                                        $lang->formatNum( $row['count'] )
                                );
 
-                               $rows[] = Html::rawElement( 'tr', array(), 
join( '', $cells ) );
+                               $rows[] = Html::rawElement( 'tr', [], join( '', 
$cells ) );
                        }
                        $this->getOutput()->addHTML(
-                               Html::rawElement( 'table', array( 'class' => 
'wikitable sortable mw-apifeatureusage' ),
-                                       Html::rawElement( 'thead', array(),
-                                               Html::rawElement( 'tr', array(),
-                                                       Html::rawElement( 'th', 
array(),
+                               Html::rawElement( 'table', [ 'class' => 
'wikitable sortable mw-apifeatureusage' ],
+                                       Html::rawElement( 'thead', [],
+                                               Html::rawElement( 'tr', [],
+                                                       Html::rawElement( 'th', 
[],
                                                                $this->msg( 
'apifeatureusage-column-feature' )->parse()
                                                        ) .
-                                                       Html::rawElement( 'th', 
array(),
+                                                       Html::rawElement( 'th', 
[],
                                                                $this->msg( 
'apifeatureusage-column-date' )->parse()
                                                        ) .
-                                                       Html::rawElement( 'th', 
array(),
+                                                       Html::rawElement( 'th', 
[],
                                                                $this->msg( 
'apifeatureusage-column-uses' )->parse()
                                                        )
                                                )
                                        ) .
-                                       Html::rawElement( 'tbody', array(), 
join( '', $rows ) )
+                                       Html::rawElement( 'tbody', [], join( 
'', $rows ) )
                                )
                        );
                }
@@ -119,8 +121,8 @@
 
        public function onSubmit( $data, $form ) {
                $agent = $data['agent'];
-               $start = new MWTimestamp( $data['dates'][0] . 'T00:00:00Z'  );
-               $end = new MWTimestamp( $data['dates'][1] . 'T23:59:59Z'  );
+               $start = new MWTimestamp( $data['dates'][0] . 'T00:00:00Z' );
+               $end = new MWTimestamp( $data['dates'][1] . 'T23:59:59Z' );
 
                return $this->engine->execute( $agent, $start, $end );
        }
diff --git a/composer.json b/composer.json
index fa2d6cd..124d0af 100644
--- a/composer.json
+++ b/composer.json
@@ -1,10 +1,13 @@
 {
        "require-dev": {
-               "jakub-onderka/php-parallel-lint": "0.9.2"
+               "jakub-onderka/php-parallel-lint": "0.9.2",
+               "mediawiki/mediawiki-codesniffer": "0.7.2"
        },
        "scripts": {
                "test": [
-                       "parallel-lint . --exclude node_modules --exclude 
vendor"
-               ]
+                       "parallel-lint . --exclude node_modules --exclude 
vendor",
+                       "phpcs -p -s"
+               ],
+               "fix": "phpcbf"
        }
 }
diff --git a/extension.json b/extension.json
index 705d6a5..2c00f19 100644
--- a/extension.json
+++ b/extension.json
@@ -6,6 +6,9 @@
        "descriptionmsg": "apifeatureusage-desc",
        "license-name": "GPL-2.0+",
        "type": "specialpage",
+       "requires": {
+               "MediaWiki": ">= 1.28.0"
+       },
        "ConfigRegistry": {
                "ApiFeatureUsage": "GlobalVarConfig::newInstance"
        },
diff --git a/phpcs.xml b/phpcs.xml
new file mode 100644
index 0000000..9c09ce9
--- /dev/null
+++ b/phpcs.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0"?>
+<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>htmlform</exclude-pattern>
+</ruleset>

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1fa1372c43627645bfbd9cb1b35f7998ae2e1c20
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ApiFeatureUsage
Gerrit-Branch: master
Gerrit-Owner: Anomie <bjor...@wikimedia.org>

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

Reply via email to