Umherirrender has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/358044 )

Change subject: Make phpcs pass - special / tests
......................................................................

Make phpcs pass - special / tests

Change-Id: Ie6e5bf3999e8514050ed80a21b7c161a27373aa9
---
M special/SpecialBannerAllocation.php
M special/SpecialCNReporter.php
M special/SpecialCentralNotice.php
M special/SpecialCentralNoticeBanners.php
M special/SpecialCentralNoticeLogs.php
M special/SpecialGlobalAllocation.php
M tests/AllocationCalculatorTest.php
M tests/CentralNoticeTest.php
M tests/CentralNoticeTestFixtures.php
9 files changed, 68 insertions(+), 61 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CentralNotice 
refs/changes/44/358044/1

diff --git a/special/SpecialBannerAllocation.php 
b/special/SpecialBannerAllocation.php
index 72d949c..242778d 100644
--- a/special/SpecialBannerAllocation.php
+++ b/special/SpecialBannerAllocation.php
@@ -105,7 +105,7 @@
                $htmlOut .= Html::element( 'h2', array(), $this->msg( 
'centralnotice-view-allocation' )->text() );
                $htmlOut .= Xml::tags( 'p', null, $this->msg( 
'centralnotice-allocation-instructions' )->text() );
 
-               $htmlOut .= Html::openElement( 'table', array ( 'id' => 
'envpicker', 'cellpadding' => 7 ) );
+               $htmlOut .= Html::openElement( 'table', array( 'id' => 
'envpicker', 'cellpadding' => 7 ) );
                $htmlOut .= Html::openElement( 'tr' );
                $htmlOut .= Xml::tags( 'td',
                        array( 'style' => 'width: 20%;' ),
@@ -130,7 +130,7 @@
                $languages = Language::fetchLanguageNames( 
$this->getLanguage()->getCode() );
                // Make sure the site language is in the list; a custom 
language code
                // might not have a defined name...
-               if( !array_key_exists( $wgLanguageCode, $languages ) ) {
+               if ( !array_key_exists( $wgLanguageCode, $languages ) ) {
                        $languages[$wgLanguageCode] = $wgLanguageCode;
                }
 
@@ -138,7 +138,7 @@
 
                $htmlOut .= Html::openElement( 'select', array( 'name' => 
'language' ) );
 
-               foreach( $languages as $code => $name ) {
+               foreach ( $languages as $code => $name ) {
                        $htmlOut .= Xml::option(
                                $this->msg( 'centralnotice-language-listing', 
$code, $name )->text(),
                                $code, $code === $this->language );
@@ -156,7 +156,7 @@
 
                $htmlOut .= Html::openElement( 'select', array( 'name' => 
'country' ) );
 
-               foreach( $countries as $code => $name ) {
+               foreach ( $countries as $code => $name ) {
                        $htmlOut .= Xml::option( $name, $code, $code === 
$this->location );
                }
 
@@ -193,9 +193,9 @@
 
                // Obtain all banners & campaigns
                $request = $this->getRequest();
-               $project = $request->getText('project');
-               $country = $request->getText('country');
-               $language = $request->getText('language');
+               $project = $request->getText( 'project' );
+               $country = $request->getText( 'country' );
+               $language = $request->getText( 'language' );
 
                // Begin building HTML
                $htmlOut = '';
@@ -209,7 +209,7 @@
 
                // Iterate through each possible device type and get allocation 
information
                $devices = CNDeviceTarget::getAvailableDevices();
-               foreach( $devices as $deviceId => $deviceData ) {
+               foreach ( $devices as $deviceId => $deviceData ) {
                        $htmlOut .= Html::openElement(
                                'div',
                                array(
@@ -274,7 +274,7 @@
         */
        public function getTable( $type, $banners ) {
                $htmlOut = Html::openElement( 'table',
-                       array ( 'cellpadding' => 9, 'class' => 'wikitable 
sortable', 'style' => 'margin: 1em 0;' )
+                       array( 'cellpadding' => 9, 'class' => 'wikitable 
sortable', 'style' => 'margin: 1em 0;' )
                );
                $htmlOut .= Html::element( 'h4', array(), $type );
 
@@ -298,7 +298,7 @@
        public function createRows( $banners ) {
                $viewCampaign = $this->getTitleFor( 'CentralNotice' );
                $htmlOut = '';
-               if (count($banners) > 0) {
+               if ( count( $banners ) > 0 ) {
                        foreach ( $banners as $banner ) {
                                $percentage = sprintf( "%0.2f", round( 
$banner['allocation'] * 100, 2 ) );
 
diff --git a/special/SpecialCNReporter.php b/special/SpecialCNReporter.php
index fec7904..242076b 100644
--- a/special/SpecialCNReporter.php
+++ b/special/SpecialCNReporter.php
@@ -32,7 +32,7 @@
        window.parent.postMessage(data, '$wgNoticeReporterDomains');
 </script></body></html>
 EOT;
-               print( $script );
+               print $script;
 
        }
 
diff --git a/special/SpecialCentralNotice.php b/special/SpecialCentralNotice.php
index f5879d8..499f0d3 100644
--- a/special/SpecialCentralNotice.php
+++ b/special/SpecialCentralNotice.php
@@ -209,7 +209,7 @@
                        if ( $timestamp === -1 ) {
                                $ts = '';
                        } else {
-                               $ts = wfTimestamp(TS_MW, $timestamp);
+                               $ts = wfTimestamp( TS_MW, $timestamp );
                        }
 
                        $out = Html::element( 'input',
@@ -740,7 +740,7 @@
                                                        $requestParamName =
                                                                
self::makeNoticeMixinControlName( $mixinName, $paramName );
 
-                                                       switch( 
$paramDef['type'] ) {
+                                                       switch ( 
$paramDef['type'] ) {
                                                                case 'string':
                                                                case 'json':
                                                                        
$paramVal = Sanitizer::removeHTMLtags(
@@ -856,7 +856,7 @@
                                $numBuckets = intval( $campaign[ 'buckets' ] );
                                $countries = Campaign::getNoticeCountries( 
$notice );
                        }
-                       $isThrottled = ($throttle < 100);
+                       $isThrottled = ( $throttle < 100 );
 
                        // Build Html
                        $htmlOut = '';
@@ -1126,7 +1126,8 @@
                // Prepare data about assigned banners to provide to 
client-side code, and
                // make it available within the fieldsset element.
 
-               $bannersForJS = array_map( function ( $banner ) {
+               $bannersForJS = array_map(
+                       function ( $banner ) {
                                return [
                                        'bannerName' => $banner->tmp_name,
                                        'bucket' => $banner->asn_bucket
@@ -1233,7 +1234,7 @@
        }
 
        function weightDropDown( $name, $selected ) {
-               $selected = intval($selected);
+               $selected = intval( $selected );
 
                if ( $this->editable ) {
                        $html = Html::openElement( 'select', array( 'name' => 
$name ) );
@@ -1624,11 +1625,11 @@
 
        protected function makeShortList( $all, $list ) {
                global $wgNoticeListComplementThreshold;
-               //TODO ellipsis and js/css expansion
-               if ( count($list) == count($all)  ) {
+               // TODO ellipsis and js/css expansion
+               if ( count( $list ) == count( $all ) ) {
                        return $this->getContext()->msg( 'centralnotice-all' 
)->text();
                }
-               if ( count($list) > $wgNoticeListComplementThreshold * 
count($all) ) {
+               if ( count( $list ) > $wgNoticeListComplementThreshold * count( 
$all ) ) {
                        $inverse = array_values( array_diff( $all, $list ) );
                        $txt = $this->getContext()->getLanguage()->listToText( 
$inverse );
                        return $this->getContext()->msg( 
'centralnotice-all-except', $txt )->text();
diff --git a/special/SpecialCentralNoticeBanners.php 
b/special/SpecialCentralNoticeBanners.php
index 166c94f..e355d5e 100644
--- a/special/SpecialCentralNoticeBanners.php
+++ b/special/SpecialCentralNoticeBanners.php
@@ -121,7 +121,7 @@
                $formDescriptor = $this->generateBannerListForm( 
$this->bannerFilterString );
                $htmlForm = new CentralNoticeHtmlForm( $formDescriptor, 
$this->getContext() );
 
-               $htmlForm->setId('cn-banner-manager')->
+               $htmlForm->setId( 'cn-banner-manager' )->
                        suppressDefaultSubmit()->
                        setDisplayFormat( 'div' )->
                        prepareForm()->
@@ -283,13 +283,13 @@
                                        break;
 
                                case 'archive':
-                                       return ('Archiving not yet 
implemented!');
+                                       return 'Archiving not yet implemented!';
                                        break;
 
                                case 'remove':
                                        $summary = 
$formData['removeBannerEditSummary'];
                                        $failed = array();
-                                       foreach( $formData as $element => 
$value ) {
+                                       foreach ( $formData as $element => 
$value ) {
                                                $parts = explode( '-', 
$element, 2 );
                                                if ( ( $parts[0] === 'applyTo' 
) && ( $value === true ) ) {
                                                        try {
@@ -455,7 +455,12 @@
                global $wgCentralNoticeBannerMixins, 
$wgNoticeUseTranslateExtension, $wgLanguageCode;
 
                $languages = Language::fetchLanguageNames( 
$this->getLanguage()->getCode() );
-               array_walk( $languages, function( &$val, $index ) { $val = 
"$index - $val"; } );
+               array_walk(
+                       $languages,
+                       function( &$val, $index ) {
+                               $val = "$index - $val";
+                       }
+               );
                $languages = array_flip( $languages );
 
                $banner = Banner::fromName( $this->bannerName );
@@ -490,8 +495,12 @@
                );
 
                $selected = array();
-               if ( $bannerSettings[ 'anon' ] === 1 ) { $selected[] = 
'anonymous'; }
-               if ( $bannerSettings[ 'account' ] === 1 ) { $selected[] = 
'registered'; }
+               if ( $bannerSettings[ 'anon' ] === 1 ) {
+                       $selected[] = 'anonymous';
+               }
+               if ( $bannerSettings[ 'account' ] === 1 ) {
+                       $selected[] = 'registered';
+               }
                $formDescriptor[ 'display-to' ] = array(
                        'section' => 'settings',
                        'type' => 'multiselect',
@@ -696,7 +705,7 @@
                );
 
                $links = array();
-               foreach( $banner->getIncludedTemplates() as $titleObj ) {
+               foreach ( $banner->getIncludedTemplates() as $titleObj ) {
                        $links[] = Linker::link( $titleObj );
                }
                if ( $links ) {
@@ -857,7 +866,7 @@
 
                                // Clear the edit summary field in the request 
so the form
                                // doesn't re-display the same value. Note: 
this is a hack :(
-                               $this->getRequest()->setVal( 'wpsummary', '');
+                               $this->getRequest()->setVal( 'wpsummary', '' );
 
                                return $ret;
                                break;
@@ -877,7 +886,7 @@
                /* --- Update the translations --- */
                // But only if we aren't using translate or if the preview 
language is the content language
                if ( !$wgNoticeUseTranslateExtension || 
$this->bannerLanguagePreview === $wgLanguageCode ) {
-                       foreach( $formData as $key => $value ) {
+                       foreach ( $formData as $key => $value ) {
                                if ( strpos( $key, 'message-' ) === 0 ) {
                                        $messageName = substr( $key, strlen( 
'message-' ) );
                                        $bannerMessage = 
$banner->getMessageField( $messageName );
diff --git a/special/SpecialCentralNoticeLogs.php 
b/special/SpecialCentralNoticeLogs.php
index f51b1da..5af8ac0 100644
--- a/special/SpecialCentralNoticeLogs.php
+++ b/special/SpecialCentralNoticeLogs.php
@@ -192,7 +192,7 @@
                $htmlOut .= Xml::closeElement( 'form' );
 
                // End log selection fieldset
-               //$htmlOut .= Xml::closeElement( 'fieldset' );
+               // $htmlOut .= Xml::closeElement( 'fieldset' );
 
                $out->addHTML( $htmlOut );
 
@@ -245,7 +245,7 @@
                $htmlOut = '';
 
                // Begin log fieldset
-               //$htmlOut .= Xml::openElement( 'fieldset', array( 'class' => 
'prefsection' ) );
+               // $htmlOut .= Xml::openElement( 'fieldset', array( 'class' => 
'prefsection' ) );
 
                // Show paginated list of log entries
                $htmlOut .= Xml::tags( 'div',
diff --git a/special/SpecialGlobalAllocation.php 
b/special/SpecialGlobalAllocation.php
index 5ca488c..9b3c4dd 100644
--- a/special/SpecialGlobalAllocation.php
+++ b/special/SpecialGlobalAllocation.php
@@ -130,7 +130,7 @@
                $htmlOut .= Xml::tags( 'p', null,
                        $this->msg( 'centralnotice-allocation-instructions' 
)->text() );
 
-               $htmlOut .= Html::openElement( 'table', array ( 'id' => 
'envpicker', 'cellpadding' => 7 ) );
+               $htmlOut .= Html::openElement( 'table', array( 'id' => 
'envpicker', 'cellpadding' => 7 ) );
                $htmlOut .= Html::openElement( 'tr' );
                $htmlOut .= Xml::tags( 'td',
                        array( 'style' => 'width: 20%;' ),
@@ -157,7 +157,7 @@
                $languages = Language::fetchLanguageNames( 
$this->getLanguage()->getCode() );
                // Make sure the site language is in the list; a custom 
language code
                // might not have a defined name...
-               if( !array_key_exists( $wgLanguageCode, $languages ) ) {
+               if ( !array_key_exists( $wgLanguageCode, $languages ) ) {
                        $languages[$wgLanguageCode] = $wgLanguageCode;
                }
 
@@ -167,7 +167,7 @@
 
                $htmlOut .= Xml::option(
                        $this->msg( 'centralnotice-all' )->text(), '', '' === 
$this->language );
-               foreach( $languages as $code => $name ) {
+               foreach ( $languages as $code => $name ) {
                        $htmlOut .= Xml::option(
                                $this->msg( 'centralnotice-language-listing', 
$code, $name )->text(),
                                $code, $code === $this->language );
@@ -187,7 +187,7 @@
 
                $htmlOut .= Xml::option(
                        $this->msg( 'centralnotice-all' )->text(), '', '' === 
$this->location );
-               foreach( $countries as $code => $name ) {
+               foreach ( $countries as $code => $name ) {
                        $htmlOut .= Xml::option( $name, $code, $code === 
$this->location );
                }
 
@@ -280,7 +280,7 @@
                                $this->msg( 'centralnotice-notice-heading', 
$grouping['label'] )->text() );
 
                        $htmlOut .= Html::openElement( 'table',
-                               array ( 'cellpadding' => 9, 'class' => 
'wikitable', 'style' => 'margin: 1em 0;' )
+                               array( 'cellpadding' => 9, 'class' => 
'wikitable', 'style' => 'margin: 1em 0;' )
                        );
                        $htmlOut .= Html::openElement( 'tr' );
                        $htmlOut .= Html::element( 'th', array( 'width' => 
'30%' ),
@@ -315,7 +315,7 @@
                                $grouping['a_project'],
                                $grouping['a_country'],
                                $grouping['a_language'],
-                               $grouping['a_num_buckets'] //XXX
+                               $grouping['a_num_buckets'] // XXX
                        );
                }
 
@@ -368,7 +368,7 @@
                                $result = array( $result );
 
                                foreach ( $excludeKeys as $key ) {
-                                       foreach( $result as $row ) {
+                                       foreach ( $result as $row ) {
                                                if ( 
CampaignCriteria::intersect( $row, $this->campaigns[$key] ) ) {
                                                        $excluding[] = 
$this->campaigns[$key]['name'];
                                                        $result = 
CampaignCriteria::difference(
@@ -461,7 +461,6 @@
                // This is annoying.  Within the campaign, banners usually vary 
by user
                // logged-in status, and bucket.  Determine the allocations and
                // collapse any dimensions which do not vary.
-               //
                // TODO: the allocation hash should also be used to collapse 
groupings which
                // are identical because of e.g. z-index
                $campaignIds = array();
@@ -481,18 +480,18 @@
                                );
                        }
                }
-               $device = 'desktop'; //XXX
+               $device = 'desktop'; // XXX
                $hashes = array();
                foreach ( array( true, false ) as $isAnon ) {
                        for ( $bucket = 0; $bucket < $numBuckets; $bucket++ ) {
-                               $device = 'desktop'; //XXX
+                               $device = 'desktop'; // XXX
 
                                $status = $isAnon ?
                                        AllocationCalculator::ANONYMOUS :
                                        AllocationCalculator::LOGGED_IN;
 
                                $campaigns = self::filterCampaigns(
-                                       $this->campaigns, $country, $language, 
$project);
+                                       $this->campaigns, $country, $language, 
$project );
 
                                $variations[$isAnon][$bucket] =
                                        
AllocationCalculator::filterAndAllocate( $country,
@@ -520,9 +519,9 @@
                $variesBucket = ( $numBuckets > 1 );
 
                $htmlOut = Html::openElement( 'table',
-                       array ( 'cellpadding' => 9, 'class' => 'wikitable 
sortable', 'style' => 'margin: 1em 0;' )
+                       array( 'cellpadding' => 9, 'class' => 'wikitable 
sortable', 'style' => 'margin: 1em 0;' )
                );
-               //$htmlOut .= Html::element( 'caption', array( 'style' => 
'font-size: 1.2em;' ), $caption );
+               // $htmlOut .= Html::element( 'caption', array( 'style' => 
'font-size: 1.2em;' ), $caption );
 
                $htmlOut .= Html::openElement( 'tr' );
                $htmlOut .= Html::element( 'th', array( 'width' => '5%' ),
@@ -623,7 +622,7 @@
                                )
                        );
                } else {
-                       $htmlOut .= Html::openElement('td');
+                       $htmlOut .= Html::openElement( 'td' );
                        $htmlOut .= Xml::tags( 'p', null, $this->msg( 
'centralnotice-no-allocation' )->text() );
                }
 
diff --git a/tests/AllocationCalculatorTest.php 
b/tests/AllocationCalculatorTest.php
index 79d86bb..9c2db4b 100644
--- a/tests/AllocationCalculatorTest.php
+++ b/tests/AllocationCalculatorTest.php
@@ -78,7 +78,7 @@
                                $expectedCampaign = 
$expectedAllocations[$campaignName];
 
                                $this->assertEquals(
-                                       round( $expectedCampaign['allocation'], 
3),
+                                       round( $expectedCampaign['allocation'], 
3 ),
                                        round( $campaign['allocation'], 3 ),
                                        $fixtureIdMsg . " Campaign 
{$campaignName} allocation."
                                );
@@ -116,7 +116,7 @@
 
                                                // Test the banner was expected 
and was correctly allocated
                                                $this->assertTrue(
-                                                       array_key_exists( 
$bannerName, $expectedBanners),
+                                                       array_key_exists( 
$bannerName, $expectedBanners ),
                                                        $fixtureIdMsg .
                                                                " Banner 
${bannerName} for " .
                                                                "campaign 
{$campaignName} not expected."
diff --git a/tests/CentralNoticeTest.php b/tests/CentralNoticeTest.php
index cd51e5d..7cb71c7 100644
--- a/tests/CentralNoticeTest.php
+++ b/tests/CentralNoticeTest.php
@@ -55,7 +55,7 @@
                        'mixins' => '[]',
                );
 
-               //get User
+               // get User
                $this->userUser = User::newFromName( 'TestUser' );
                if ( !$this->userUser->getID() ) {
                        $this->userUser = User::createNew( 'TestUser', array(
@@ -90,13 +90,13 @@
                parent::tearDown();
                Campaign::removeCampaign( 'PHPUnitTestCampaign', 
$this->userUser );
                Campaign::removeTemplateFor( 'PHPUnitTestCampaign', 
'PHPUnitTestBanner' );
-               Banner::removeTemplate ( 'PHPUnitTestBanner', $this->userUser );
+               Banner::removeTemplate( 'PHPUnitTestBanner', $this->userUser );
                $this->fixture->tearDownTestCases();
        }
 
        public function testDropDownList() {
                $text = 'Weight';
-               $values = range ( 0, 50, 10 );
+               $values = range( 0, 50, 10 );
                $this->assertEquals(
                        "*Weight\n**0\n**10\n**20\n**30\n**40\n**50\n",
                        CentralNotice::dropDownList( $text, $values ) );
@@ -106,7 +106,7 @@
                $projects = Campaign::getNoticeProjects( 'PHPUnitTestCampaign' 
);
                sort( $projects );
                $this->assertEquals(
-                       array ( 'wikibooks', 'wikipedia' ),
+                       array( 'wikibooks', 'wikipedia' ),
                        $projects
                );
        }
@@ -115,7 +115,7 @@
                $languages = Campaign::getNoticeLanguages( 
'PHPUnitTestCampaign' );
                sort( $languages );
                $this->assertEquals(
-                       array ( 'de', 'en' ),
+                       array( 'de', 'en' ),
                        $languages
                );
        }
@@ -124,7 +124,7 @@
                $countries = Campaign::getNoticeCountries( 
'PHPUnitTestCampaign' );
                sort( $countries );
                $this->assertEquals(
-                       array ( 'AF', 'US' ),
+                       array( 'AF', 'US' ),
                        $countries
                );
        }
diff --git a/tests/CentralNoticeTestFixtures.php 
b/tests/CentralNoticeTestFixtures.php
index 221dbe8..87835ab 100644
--- a/tests/CentralNoticeTestFixtures.php
+++ b/tests/CentralNoticeTestFixtures.php
@@ -94,7 +94,7 @@
 
        /**
         * Add defaults to the test case setup specification, for legacy tests 
that
-        * don't use the shared JSON fixture data. 
+        * don't use the shared JSON fixture data.
         *
         * @param array $testCaseSetup A data structure with the setup section 
of a
         *  test case specification
@@ -184,7 +184,7 @@
        }
 
        /**
-        * Add dummy banner properties throughout a test case setup 
specification. 
+        * Add dummy banner properties throughout a test case setup 
specification.
         *
         * @param array $testCaseSetup A data structure with the setup section 
of a
         *  test case specification
@@ -294,9 +294,8 @@
                                );
 
                                $bannerObj = Banner::fromName( 
$bannerSpec['name'] );
-                               
-                               if ( isset( $bannerSpec['bucket'] ) ) {
 
+                               if ( isset( $bannerSpec['bucket'] ) ) {
                                        $bucket = $bannerSpec['bucket'];
                                        if ( $bucket < 0 || $bucket > 
$wgNoticeNumberOfBuckets ) {
                                                throw new RangeException( 
'Bucket out of range' );
@@ -351,7 +350,8 @@
         * @param array $actual Actual choices data structure
         */
        function assertChoicesEqual( MediaWikiTestCase $testClass, $expected, 
$actual,
-                       $message='' ) {
+               $message=''
+       ) {
 
                // The order of the numerically indexed arrays in this data 
structure
                // shouldn't matter, so sort all of those by value.
@@ -371,7 +371,7 @@
                array_multisort( $a );
 
                foreach ( $a as &$v ) {
-                       if ( is_array ( $v ) ) {
+                       if ( is_array( $v ) ) {
                                $this->deepMultisort( $v );
                        }
                }
@@ -392,7 +392,6 @@
         * @param string[] $deviceNames
         */
        protected function ensureDevices( $deviceNames ) {
-
                if ( !$this->knownDevices ) {
                        $this->knownDevices = 
CNDeviceTarget::getAvailableDevices( true );
                }
@@ -424,11 +423,10 @@
         * a test method.)
         */
        public static function allocationsTestCasesProvision() {
-
                $data = CentralNoticeTestFixtures::allocationsData();
                $dataForTests = array();
 
-               foreach  ( $data['test_cases'] as $name => $testCase ) {
+               foreach ( $data['test_cases'] as $name => $testCase ) {
                        $dataForTests[] = array( $name, $testCase );
                }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie6e5bf3999e8514050ed80a21b7c161a27373aa9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralNotice
Gerrit-Branch: master
Gerrit-Owner: Umherirrender <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to