MaxSem has uploaded a new change for review.

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

Change subject: CodeSniffer fixes
......................................................................

CodeSniffer fixes

Change-Id: I8bdcd2250bd3163fe40ce4685eb04bffe53afdca
---
M includes/ApiQueryExtracts.php
M includes/ExtractFormatter.php
M includes/Hooks.php
M tests/phpunit/ExtractFormatterTest.php
4 files changed, 83 insertions(+), 84 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TextExtracts 
refs/changes/46/312446/1

diff --git a/includes/ApiQueryExtracts.php b/includes/ApiQueryExtracts.php
index ce7f70a..e704cef 100644
--- a/includes/ApiQueryExtracts.php
+++ b/includes/ApiQueryExtracts.php
@@ -48,7 +48,7 @@
        /**
         * @var array
         */
-       private $supportedContentModels  = array( 'wikitext' );
+       private $supportedContentModels = [ 'wikitext' ];
 
        public function __construct( $query, $moduleName, Config $conf ) {
                parent::__construct( $query, $moduleName, 'ex' );
@@ -91,9 +91,9 @@
                        }
 
                        if ( $isXml ) {
-                               $fit = $result->addValue( array( 'query', 
'pages', $id ), 'extract', array( '*' => $text ) );
+                               $fit = $result->addValue( [ 'query', 'pages', 
$id ], 'extract', [ '*' => $text ] );
                        } else {
-                               $fit = $result->addValue( array( 'query', 
'pages', $id ), 'extract', $text );
+                               $fit = $result->addValue( [ 'query', 'pages', 
$id ], 'extract', $text );
                        }
                        if ( !$fit ) {
                                $this->setContinueEnumParameter( 'continue', 
$continue + $count - 1 );
@@ -196,33 +196,33 @@
                                return $text;
                        }
                }
-               $request = array(
+               $request = [
                        'action' => 'parse',
                        'page' => $page->getTitle()->getPrefixedText(),
                        'prop' => 'text'
-               );
+               ];
                if ( $this->params['intro'] ) {
                        $request['section'] = 0;
                }
                // in case of cache miss, render just the needed section
-               $api = new ApiMain( new FauxRequest( $request ) );
+               $api = new ApiMain( new FauxRequest( $request ) );
                try {
                        $api->execute();
-                       $data = $api->getResult()->getResultData( null, array(
-                               'BC' => array(),
-                               'Types' => array(),
-                       ) );
+                       $data = $api->getResult()->getResultData( null, [
+                               'BC' => [],
+                               'Types' => [],
+                       ] );
                } catch ( UsageException $e ) {
                        if ( $e->getCodeString() === 'nosuchsection' ) {
                                // Looks like we tried to get the intro to a 
page without
                                // sections!  Lets just grab what we can get.
                                unset( $request['section'] );
-                               $api = new ApiMain( new FauxRequest( $request ) 
);
+                               $api = new ApiMain( new FauxRequest( $request ) 
);
                                $api->execute();
-                               $data = $api->getResult()->getResultData( null, 
array(
-                                       'BC' => array(),
-                                       'Types' => array(),
-                               ) );
+                               $data = $api->getResult()->getResultData( null, 
[
+                                       'BC' => [],
+                                       'Types' => [],
+                               ] );
                        } else {
                                // Some other unexpected error - lets just 
report it to the user
                                // on the off chance that is the right thing.
@@ -304,7 +304,7 @@
         */
        private function tidy( $text ) {
                if ( $this->getConfig()->get( 'UseTidy' ) && 
!$this->params['plaintext'] ) {
-                       $text = trim ( MWTidy::tidy( $text ) );
+                       $text = trim( MWTidy::tidy( $text ) );
                }
                return $text;
        }
@@ -312,7 +312,7 @@
        private function doSections( $text ) {
                $text = preg_replace_callback(
                        "/" . ExtractFormatter::SECTION_MARKER_START . '(\d)'. 
ExtractFormatter::SECTION_MARKER_END . "(.*?)$/m",
-                       array( $this, 'sectionCallback' ),
+                       [ $this, 'sectionCallback' ],
                        $text
                );
                return $text;
@@ -336,44 +336,44 @@
        }
 
        public function getAllowedParams() {
-               return array(
-                       'chars' => array(
+               return [
+                       'chars' => [
                                ApiBase::PARAM_TYPE => 'integer',
                                ApiBase::PARAM_MIN => 1,
-                       ),
-                       'sentences' => array(
+                       ],
+                       'sentences' => [
                                ApiBase::PARAM_TYPE => 'integer',
                                ApiBase::PARAM_MIN => 1,
                                ApiBase::PARAM_MAX => 10,
-                       ),
-                       'limit' => array(
+                       ],
+                       'limit' => [
                                ApiBase::PARAM_DFLT => 1,
                                ApiBase::PARAM_TYPE => 'limit',
                                ApiBase::PARAM_MIN => 1,
                                ApiBase::PARAM_MAX => 20,
                                ApiBase::PARAM_MAX2 => 20,
-                       ),
+                       ],
                        'intro' => false,
                        'plaintext' => false,
-                       'sectionformat' => array(
-                               ApiBase::PARAM_TYPE => array( 'plain', 'wiki', 
'raw' ),
+                       'sectionformat' => [
+                               ApiBase::PARAM_TYPE => [ 'plain', 'wiki', 'raw' 
],
                                ApiBase::PARAM_DFLT => 'wiki',
-                       ),
-                       'continue' => array(
+                       ],
+                       'continue' => [
                                ApiBase::PARAM_TYPE => 'integer',
                                ApiBase::PARAM_HELP_MSG => 
'api-help-param-continue',
-                       ),
-               );
+                       ],
+               ];
        }
 
        /**
         * @see ApiBase::getExamplesMessages()
         */
        protected function getExamplesMessages() {
-               return array(
+               return [
                        'action=query&prop=extracts&exchars=175&titles=Therion'
                                => 'apihelp-query+extracts-example-1',
-               );
+               ];
        }
 
        public function getHelpUrls() {
diff --git a/includes/ExtractFormatter.php b/includes/ExtractFormatter.php
index 22dd787..30a88f0 100644
--- a/includes/ExtractFormatter.php
+++ b/includes/ExtractFormatter.php
@@ -45,7 +45,7 @@
                if ( $plainText ) {
                        $this->flattenAllTags();
                } else {
-                       $this->flatten( array( 'a' ) );
+                       $this->flatten( [ 'a' ] );
                }
        }
 
@@ -64,7 +64,7 @@
        public function onHtmlReady( $html ) {
                if ( $this->plainText ) {
                        $html = preg_replace( '/\s*(<h([1-6])\b)/i',
-                               "\n\n" . self::SECTION_MARKER_START . '$2' . 
self::SECTION_MARKER_END . '$1' ,
+                               "\n\n" . self::SECTION_MARKER_START . '$2' . 
self::SECTION_MARKER_END . '$1',
                                $html
                        );
                }
@@ -80,21 +80,21 @@
         */
        public static function getFirstSentences( $text, 
$requestedSentenceCount ) {
                // Based on code from OpenSearchXml by Brion Vibber
-               $endchars = array(
+               $endchars = [
                        '[^\p{Lu}]\.(?:[ \n]|$)', '[\!\?](?:[ \n]|$)', // 
regular ASCII
                        '。', // full-width ideographic full-stop
                        '.', '!', '?', // double-width roman forms
                        '。', // half-width ideographic full stop
-                       );
+                       ];
 
                $endgroup = implode( '|', $endchars );
                $end = "(?:$endgroup)";
                $sentence = ".+?$end+";
                $requestedSentenceCount = intval( $requestedSentenceCount );
                $regexp = "/^($sentence){1,{$requestedSentenceCount}}/u";
-               $matches = array();
+               $matches = [];
                $res = preg_match( $regexp, $text, $matches );
-               if( $res ) {
+               if ( $res ) {
                        $text = trim( $matches[0] );
                } else {
                        if ( $res === false ) {
diff --git a/includes/Hooks.php b/includes/Hooks.php
index 06f291f..7aabce2 100644
--- a/includes/Hooks.php
+++ b/includes/Hooks.php
@@ -2,7 +2,6 @@
 
 namespace TextExtracts;
 
-
 use ApiMain;
 use ApiResult;
 use ConfigFactory;
@@ -22,17 +21,17 @@
                }
                $pageIds = array_keys( $results );
                $api = new ApiMain( new FauxRequest(
-                       array(
+                       [
                                'action' => 'query',
                                'prop' => 'extracts',
                                'explaintext' => true,
                                'exintro' => true,
                                'exlimit' => count( $results ),
                                'pageids' => implode( '|', $pageIds ),
-                       ) )
+                       ] )
                );
                $api->execute();
-               $data = $api->getResult()->getResultData( array( 'query', 
'pages' ) );
+               $data = $api->getResult()->getResultData( [ 'query', 'pages' ] 
);
                foreach ( $pageIds as $id ) {
                        $contentKey = isset( 
$data[$id]['extract'][ApiResult::META_CONTENT] )
                                ? $data[$id]['extract'][ApiResult::META_CONTENT]
diff --git a/tests/phpunit/ExtractFormatterTest.php 
b/tests/phpunit/ExtractFormatterTest.php
index 5501e2f..07366e8 100644
--- a/tests/phpunit/ExtractFormatterTest.php
+++ b/tests/phpunit/ExtractFormatterTest.php
@@ -22,29 +22,29 @@
        public function provideExtracts() {
                $dutch = '<b>Dutch</b> (<span class="unicode haudio" 
style="white-space:nowrap;"><span class="fn"><a 
href="/wiki/File:Nl-Nederlands.ogg" title="About this sound"><img alt="About 
this sound" 
src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/8a/Loudspeaker.svg/11px-Loudspeaker.svg.png";
 width="11" height="11" 
srcset="https://upload.wikimedia.org/wikipedia/commons/thumb/8/8a/Loudspeaker.svg/17px-Loudspeaker.svg.png
 1.5x, 
https://upload.wikimedia.org/wikipedia/commons/thumb/8/8a/Loudspeaker.svg/22px-Loudspeaker.svg.png
 2x" /></a>&#160;<a 
href="https://upload.wikimedia.org/wikipedia/commons/d/db/Nl-Nederlands.ogg"; 
class="internal" 
title="Nl-Nederlands.ogg"><i>Nederlands</i></a></span>&#160;<small 
class="metadata audiolinkinfo" style="cursor:help;">(<a 
href="/w/index.php?title=Wikipedia:Media_help&amp;action=edit&amp;redlink=1" 
class="new" title="Wikipedia:Media help (page does not exist)"><span 
style="cursor:help;">help</span></a>·<a href="/wiki/File:Nl-Nederlands.ogg" 
title="File:Nl-Nederlands.ogg"><span 
style="cursor:help;">info</span></a>)</small></span>) is a <a 
href="/w/index.php?title=West_Germanic_languages&amp;action=edit&amp;redlink=1" 
class="new" title="West Germanic languages (page does not exist)">West Germanic 
language</a> and the native language of most of the population of the <a 
href="/w/index.php?title=Netherlands&amp;action=edit&amp;redlink=1" class="new" 
title="Netherlands (page does not exist)">Netherlands</a>';
 
-               return array(
-                       array(
+               return [
+                       [
                                "Dutch ( Nederlands ) is a West Germanic 
language and the native language of most of the population of the Netherlands",
                                $dutch,
                                true,
-                       ),
+                       ],
 
-                       array(
+                       [
                                "<span><span lang=\"baz\">qux</span></span>",
                                '<span class="foo"><span 
lang="baz">qux</span></span>',
                                false,
-                       ),
-                       array(
+                       ],
+                       [
                                "<span><span lang=\"baz\">qux</span></span>",
                                '<span style="foo: bar;"><span 
lang="baz">qux</span></span>',
                                false,
-                       ),
-                       array(
+                       ],
+                       [
                                "<span><span lang=\"qux\">quux</span></span>",
                                '<span class="foo"><span style="bar: baz;" 
lang="qux">quux</span></span>',
                                false,
-                       ),
-               );
+                       ],
+               ];
        }
 
        /**
@@ -58,68 +58,68 @@
        }
 
        public function provideGetFirstSentences() {
-               return array(
-                       array(
+               return [
+                       [
                                'Foo is a bar. Such a smart boy. But completely 
useless.',
                                2,
                                'Foo is a bar. Such a smart boy.',
-                       ),
-                       array(
+                       ],
+                       [
                                'Foo is a bar. Such a smart boy. But completely 
useless.',
                                1,
                                'Foo is a bar.',
-                       ),
-                       array(
+                       ],
+                       [
                                'Foo is a bar. Such a smart boy.',
                                2,
                                'Foo is a bar. Such a smart boy.',
-                       ),
-                       array(
+                       ],
+                       [
                                'Foo is a bar.',
                                1,
                                'Foo is a bar.',
-                       ),
-                       array(
+                       ],
+                       [
                                'Foo is a bar.',
                                2,
                                'Foo is a bar.',
-                       ),
-                       array(
+                       ],
+                       [
                                '',
                                1,
                                '',
-                       ),
+                       ],
                        // Exclamation points too!!!
-                       array(
+                       [
                                'Foo is a bar! Such a smart boy! But completely 
useless!',
                                1,
                                'Foo is a bar!',
-                       ),
+                       ],
                        // A tricky one
-                       array(
+                       [
                                "Acid phosphatase (EC 3.1.3.2) is a chemical 
you don't want to mess with. Polyvinyl acetate, however, is another story.",
                                1,
                                "Acid phosphatase (EC 3.1.3.2) is a chemical 
you don't want to mess with.",
-                       ),
+                       ],
                        // Bug T118621
-                       array(
+                       [
                                'Foo was born in 1977. He enjoys listening to 
Siouxsie and the Banshees.',
                                1,
                                'Foo was born in 1977.',
-                       ),
+                       ],
                        // Bug T115795 - Test no cropping after initials
-                       array(
+                       [
                                'P.J. Harvey is a singer. She is awesome!',
                                1,
                                'P.J. Harvey is a singer.',
-                       ),
+                       ],
                        // Bug T115817 - Non-breaking space is not a delimiter
-                       array(
+                       [
                                html_entity_decode( 'Pigeons 
(lat.&nbsp;Columbidae) are birds. They primarily feed on seeds.' ),
                                1,
                                html_entity_decode( 'Pigeons 
(lat.&nbsp;Columbidae) are birds.' ),
-                       ),
-               );
+                       ],
+               ];
        }
 
        /**
@@ -134,13 +134,13 @@
 
        public function provideGetFirstChars() {
                $text = 'Lullzy lulz are lullzy!';
-               return array(
-                       //array( $text, 0, '' ),
-                       array( $text, 100, $text ),
-                       array( $text, 1, 'Lullzy' ),
-                       array( $text, 6, 'Lullzy' ),
-                       //array( $text, 7, 'Lullzy' ),
-                       array( $text, 8, 'Lullzy lulz' ),
-               );
+               return [
+                       // [ $text, 0, '' ],
+                       [ $text, 100, $text ],
+                       [ $text, 1, 'Lullzy' ],
+                       [ $text, 6, 'Lullzy' ],
+                       // [ $text, 7, 'Lullzy' ],
+                       [ $text, 8, 'Lullzy lulz' ],
+               ];
        }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8bdcd2250bd3163fe40ce4685eb04bffe53afdca
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TextExtracts
Gerrit-Branch: master
Gerrit-Owner: MaxSem <maxsem.w...@gmail.com>

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

Reply via email to