jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/356958 )
Change subject: Add phpcs and make pass ...................................................................... Add phpcs and make pass Change-Id: I8c322b466ac8d40df52c80fa5a78153a592d5a98 --- M MapSources.hooks.php M MapSources.i18n.alias.php M MapSources.i18n.magic.php M MapSources.php M MapSources_body.php M MapSources_math.php M MapSources_transform.php M composer.json A phpcs.xml 9 files changed, 125 insertions(+), 111 deletions(-) Approvals: Legoktm: Looks good to me, approved jenkins-bot: Verified diff --git a/MapSources.hooks.php b/MapSources.hooks.php index fdf907a..fb12077 100644 --- a/MapSources.hooks.php +++ b/MapSources.hooks.php @@ -70,7 +70,9 @@ break; case 'precision': $precision = $parts[1]; - if ( !is_numeric( $precision ) ) $precision = 4; + if ( !is_numeric( $precision ) ) { + $precision = 4; + } break; } } @@ -135,7 +137,7 @@ } } - $args = array(); + $args = []; $lat = new MapSourcesMath( $lat, $precision, 'lat', 2 ); $long = new MapSourcesMath( $long, $precision, 'long', 2 ); @@ -171,8 +173,7 @@ if ( $long->error == 0 ) { $args[] = $long->dec; - } - else { + } else { $args[] = '0'; } diff --git a/MapSources.i18n.alias.php b/MapSources.i18n.alias.php index ccd0209..50439a9 100644 --- a/MapSources.i18n.alias.php +++ b/MapSources.i18n.alias.php @@ -5,81 +5,80 @@ * @file * @ingroup Extensions */ -// @codingStandardsIgnoreFile -$specialPageAliases = array(); +$specialPageAliases = []; /** English (English) */ -$specialPageAliases['en'] = array( - 'MapSources' => array( 'MapSources' ), -); +$specialPageAliases['en'] = [ + 'MapSources' => [ 'MapSources' ], +]; /** Arabic (العربية) */ -$specialPageAliases['ar'] = array( - 'MapSources' => array( 'مصادر_الخريطة' ), -); +$specialPageAliases['ar'] = [ + 'MapSources' => [ 'مصادر_الخريطة' ], +]; /** Egyptian Arabic (مصرى) */ -$specialPageAliases['arz'] = array( - 'MapSources' => array( 'مصادر_الخريطه' ), -); +$specialPageAliases['arz'] = [ + 'MapSources' => [ 'مصادر_الخريطه' ], +]; /** Western Balochi (بلوچی رخشانی) */ -$specialPageAliases['bgn'] = array( - 'MapSources' => array( 'نخشه_ئی_زهی' ), -); +$specialPageAliases['bgn'] = [ + 'MapSources' => [ 'نخشه_ئی_زهی' ], +]; /** German (Deutsch) */ -$specialPageAliases['de'] = array( - 'MapSources' => array( 'Kartenherkunft', 'Kartenquellen' ), -); +$specialPageAliases['de'] = [ + 'MapSources' => [ 'Kartenherkunft', 'Kartenquellen' ], +]; /** Zazaki (Zazaki) */ -$specialPageAliases['diq'] = array( - 'MapSources' => array( 'ÇımeyĞeriter' ), -); +$specialPageAliases['diq'] = [ + 'MapSources' => [ 'ÇımeyĞeriter' ], +]; /** Persian (فارسی) */ -$specialPageAliases['fa'] = array( - 'MapSources' => array( 'منابع_نقشه' ), -); +$specialPageAliases['fa'] = [ + 'MapSources' => [ 'منابع_نقشه' ], +]; /** Upper Sorbian (hornjoserbsce) */ -$specialPageAliases['hsb'] = array( - 'MapSources' => array( 'Kartowe_žórła' ), -); +$specialPageAliases['hsb'] = [ + 'MapSources' => [ 'Kartowe_žórła' ], +]; /** Korean (한국어) */ -$specialPageAliases['ko'] = array( - 'MapSources' => array( '지도원본' ), -); +$specialPageAliases['ko'] = [ + 'MapSources' => [ '지도원본' ], +]; /** Macedonian (македонски) */ -$specialPageAliases['mk'] = array( - 'MapSources' => array( 'КартографскиИзвори' ), -); +$specialPageAliases['mk'] = [ + 'MapSources' => [ 'КартографскиИзвори' ], +]; /** Malayalam (മലയാളം) */ -$specialPageAliases['ml'] = array( - 'MapSources' => array( 'ഭൂപടസ്രോതസ്സുകൾ' ), -); +$specialPageAliases['ml'] = [ + 'MapSources' => [ 'ഭൂപടസ്രോതസ്സുകൾ' ], +]; /** Dutch (Nederlands) */ -$specialPageAliases['nl'] = array( - 'MapSources' => array( 'MapBronnen' ), -); +$specialPageAliases['nl'] = [ + 'MapSources' => [ 'MapBronnen' ], +]; /** Vietnamese (Tiếng Việt) */ -$specialPageAliases['vi'] = array( - 'MapSources' => array( 'Nguồn_bản_đồ' ), -); +$specialPageAliases['vi'] = [ + 'MapSources' => [ 'Nguồn_bản_đồ' ], +]; /** Simplified Chinese (中文(简体)) */ -$specialPageAliases['zh-hans'] = array( - 'MapSources' => array( '地图来源' ), -); +$specialPageAliases['zh-hans'] = [ + 'MapSources' => [ '地图来源' ], +]; /** Traditional Chinese (中文(繁體)) */ -$specialPageAliases['zh-hant'] = array( - 'MapSources' => array( '地圖資源' ), -); \ No newline at end of file +$specialPageAliases['zh-hant'] = [ + 'MapSources' => [ '地圖資源' ], +]; diff --git a/MapSources.i18n.magic.php b/MapSources.i18n.magic.php index ac8a227..df52810 100644 --- a/MapSources.i18n.magic.php +++ b/MapSources.i18n.magic.php @@ -1,9 +1,9 @@ <?php -$magicWords = array(); +$magicWords = []; -$magicWords['en'] = array( - 'dd2dms' => array( 0, 'dd2dms' ), - 'deg2dd' => array( 0, 'deg2dd' ), - 'geoLink' => array( 0, 'geoLink' ), -); +$magicWords['en'] = [ + 'dd2dms' => [ 0, 'dd2dms' ], + 'deg2dd' => [ 0, 'deg2dd' ], + 'geoLink' => [ 0, 'geoLink' ], +]; diff --git a/MapSources.php b/MapSources.php index e476b4a..20570af 100644 --- a/MapSources.php +++ b/MapSources.php @@ -18,7 +18,8 @@ $wgExtensionMessagesFiles['MapSourcesAlias'] = __DIR__ . '/MapSources.i18n.alias.php'; $wgExtensionMessagesFiles['MapSourcesMagic'] = __DIR__ . '/MapSources.i18n.magic.php'; /*wfWarn( - 'Deprecated PHP entry point used for MapSources extension. Please use wfLoadExtension instead, ' . + 'Deprecated PHP entry point used for MapSources extension. ' . + 'Please use wfLoadExtension instead, ' . 'see https://www.mediawiki.org/wiki/Extension_registration for more details.' );*/ return; diff --git a/MapSources_body.php b/MapSources_body.php index 6ecf8c5..fda2f81 100644 --- a/MapSources_body.php +++ b/MapSources_body.php @@ -24,7 +24,7 @@ public $long = 0; public $params = ''; public $par; - public $errorMsgs = array(); + public $errorMsgs = []; public $locName = ''; public $google = 0.1; @@ -84,13 +84,13 @@ $out->addWikiMsg( 'mapsources-summary' ); $form = - Html::rawElement( 'fieldset', array(), + Html::rawElement( 'fieldset', [], Html::element( - 'legend', array(), $this->msg( 'mapsources-search-legend' )->escaped() + 'legend', [], $this->msg( 'mapsources-search-legend' )->escaped() ) . - Html::rawElement( 'form', array( 'method' => 'get', 'action' => $wgScript ), + Html::rawElement( 'form', [ 'method' => 'get', 'action' => $wgScript ], Html::hidden( 'title', self::getTitleFor( 'MapSources' )->getPrefixedText() ) . - Html::rawElement( 'p', array(), + Html::rawElement( 'p', [], Xml::inputLabel( $this->msg( 'mapsources-coordinate' )->escaped(), 'params', 'params', 80, $defaultValue @@ -154,7 +154,7 @@ } $args = explode( " ", trim( str_replace( '=', ':', str_replace( '_', ' ', $args ) ) ) ); - $this->par = array(); + $this->par = []; foreach ( $args as $arg ) { $parts = array_map( 'trim', explode( ':', $arg, 2 ) ); if ( count( $parts ) == 2 && $parts[0] && $parts[1] ) { @@ -177,7 +177,7 @@ # setScales() code by Egil Kvaleberg <e...@kvaleberg.no> private function setScales() { if ( !isset( $this->par['scale'] ) || ( $this->par['scale'] < 100 ) ) { - $scaleByType = array( + $scaleByType = [ 'country' => 10000000, 'state' => 3000000, 'adm1st' => 1000000, @@ -188,7 +188,7 @@ 'waterbody' => 100000, 'airport' => 30000, 'landmark' => 10000 - ); + ]; if ( isset( $this->par['type'] ) && isset( $scaleByType[$this->par['type']] ) ) { $this->par['scale'] = $scaleByType[$this->par['type']]; } else { @@ -215,10 +215,10 @@ } /* Multimap fixed scales */ - $min = array( 1, 7000, 15000, 35000, 70000, 140000, 310000, - 700000, 1400000, 2800000, 6300000, 14000000, 30000000 ); - $mm = array( 5000, 10000, 20000, 50000, 100000, 200000, 500000, - 1000000, 2000000, 4000000, 10000000, 20000000, 40000000 ); + $min = [ 1, 7000, 15000, 35000, 70000, 140000, 310000, + 700000, 1400000, 2800000, 6300000, 14000000, 30000000 ]; + $mm = [ 5000, 10000, 20000, 50000, 100000, 200000, 500000, + 1000000, 2000000, 4000000, 10000000, 20000000, 40000000 ]; $i = 0; $c = count( $min ); while ( ( $this->par['scale'] >= $min[$i] ) && ( $i < $c ) ) { @@ -264,7 +264,7 @@ // otherwise, format should be /wiki/<title> (or whatever, based on $wgArticlePath) $url = parse_url( $referrer ); - $values = array(); + $values = []; if ( isset( $url['query'] ) ) { parse_str( $url['query'], $values ); } @@ -353,7 +353,7 @@ $nztmError = $errorMsg; } - $replace = array( + $replace = [ '{latdegdec}' => $this->lat->coord['dec'], '{latdegabs}' => abs( $this->lat->coord['deg'] ), '{latdegint}' => $this->lat->coord['deg'], @@ -405,7 +405,7 @@ '{ch1903error}' => $ch1903Error, '{nztmerror}' => $nztmError, '{locname}' => $this->locName - ); + ]; return strtr( $text, $replace ); } diff --git a/MapSources_math.php b/MapSources_math.php index c600afa..efcea8a 100644 --- a/MapSources_math.php +++ b/MapSources_math.php @@ -17,7 +17,7 @@ public $prec; public $step; public $error; - public $coord = array(); + public $coord = []; public function __construct( $input, $precision = 4, $dir = '', $untilStep = 1 ) { $this->newCoord( $input, $precision, $dir ); @@ -34,7 +34,7 @@ } $p = intval( $precision ); - if ( $p >= -1 && $p < 10 ) { + if ( $p >= -1 && $p < 10 ) { $this->prec = $p; } else { $this->prec = 4; @@ -151,11 +151,11 @@ } protected function getErrorMsg() { - $msg = array( 'no error', 'no parameter(s)', 'to many parameters', 'illegal characters', + $msg = [ 'no error', 'no parameter(s)', 'to many parameters', 'illegal characters', 'to many numeric parameters', 'degree out of range', 'minute out of range', 'degree no integer', 'second out of range', 'minute no integer', 'direction not last parameter', 'invalid negative value', 'wrong direction', - 'latitude out of range', 'unknown error' ); + 'latitude out of range', 'unknown error' ]; $e = -$this->error; $c = count( $msg ); @@ -168,25 +168,25 @@ } protected function toDec( $input = '' ) { - $units = array( '°', "'", '"', ' ' ); + $units = [ '°', "'", '"', ' ' ]; if ( $input == '' ) { return -1; } - $w = str_replace( array( '‘', '’', '′' ), "'", $input ); - $w = str_replace( array( "''", '“', '”', '″' ), '"', $w ); + $w = str_replace( [ '‘', '’', '′' ], "'", $input ); + $w = str_replace( [ "''", '“', '”', '″' ], '"', $w ); $w = str_replace( '−', '-', $w ); - $w = strtoupper( str_replace( array( '_', '/', "\t", "\n", "\r" ), ' ', $w ) ); - $w = str_replace( array( '°', "'", '"' ), array( '° ', "' ", '" ' ), $w ); - $w = trim( str_replace( array( 'N', 'S', 'E', 'W' ), array( ' N', ' S', ' E', ' W' ), $w ) ); + $w = strtoupper( str_replace( [ '_', '/', "\t", "\n", "\r" ], ' ', $w ) ); + $w = str_replace( [ '°', "'", '"' ], [ '° ', "' ", '" ' ], $w ); + $w = trim( str_replace( [ 'N', 'S', 'E', 'W' ], [ ' N', ' S', ' E', ' W' ], $w ) ); $w = preg_split( "/[\s]+/", $w, 5, PREG_SPLIT_NO_EMPTY ); $c = count( $w ); if ( $c < 1 || $c > 4 ) { return -2; } - $res = array( 0, 0, 0, 1 ); + $res = [ 0, 0, 0, 1 ]; for ( $i = 0; $i < $c; $i++ ) { $v = $w[$i]; @@ -264,7 +264,9 @@ return -13; } - if ( $v == 'S' || $v == 'W' ) $res[3] = -1; + if ( $v == 'S' || $v == 'W' ) { + $res[3] = -1; + } } } diff --git a/MapSources_transform.php b/MapSources_transform.php index f4aea0f..7ab3e14 100644 --- a/MapSources_transform.php +++ b/MapSources_transform.php @@ -52,32 +52,32 @@ public $lat = 0; public $long = 0; - public $ellWGS84 = array( + public $ellWGS84 = [ 'maxAxis' => 6378137.0, 'minAxis' => 6356752.315, 'ecc' => 0.081819190843, 'eccSquared' => 0.006694379990, 'flattening' => 0.003352810665, 'invFlattening' => 298.257223563 - ); - public $ellAiry1830 = array( + ]; + public $ellAiry1830 = [ 'maxAxis' => 6377563.396, 'minAxis' => 6356256.909, 'ecc' => 0.081673374328, 'eccSquared' => 0.006670540074, 'flattening' => 0.003340850640, 'invFlattening' => 299.3249647 - ); - public $ellBessel1841 = array( + ]; + public $ellBessel1841 = [ 'maxAxis' => 6377397.155, 'minAxis' => 6356078.965, 'ecc' => 0.081696829804, 'eccSquared' => 0.006674372, 'flattening' => 0.003342773182, 'invFlattening' => 299.1528128 - ); + ]; - public $utm = array( + public $utm = [ 'easting' => 0, 'northing' => 0, 'error' => -1, @@ -88,9 +88,9 @@ 'eastingOffset' => 500000.0, 'northingOffset' => 0.0, 'northingOffsetSouth' => 10000000.0 - ); + ]; public $utm33; - public $osgb36 = array( + public $osgb36 = [ 'easting' => 0, 'northing' => 0, 'ref' => '', @@ -99,13 +99,13 @@ 'eastingOffset' => 400000.0, 'northingOffset' => -100000.0, 'northingOffsetSouth' => 0.0 - ); - public $ch1903 = array( + ]; + public $ch1903 = [ 'easting' => 0, 'northing' => 0, 'error' => -1 - ); - public $nztm = array( + ]; + public $nztm = [ 'easting' => 0, 'northing' => 0, 'error' => -1, @@ -113,15 +113,14 @@ 'eastingOffset' => 1600000.0, 'northingOffset' => 0.0, 'northingOffsetSouth' => 10000000.0 - ); - + ]; public function __construct( $lat, $long ) { return $this->getValues( $lat, $long ); } protected function getValues( $lat, $long ) { - if ($lat < -90 || $lat > 90 || $long <= -180 || $long > 180) { + if ( $lat < -90 || $lat > 90 || $long <= -180 || $long > 180 ) { return false; } @@ -176,7 +175,7 @@ $utmArray['zone'] = floor( ( $long + 180.0 ) / 6 ) + 1; } - $c = floor( ($this->lat + 96) / 8 ); + $c = floor( ( $this->lat + 96 ) / 8 ); /* 000000000011111111112222 */ /* 012345678901234567890134 */ $utmArray['zoneLetter'] = substr( 'CCCDEFGHJKLMNPQRSTUVWXXX', $c, 1 ); @@ -223,7 +222,7 @@ $tan2Lat = $tanLat * $tanLat; $e2 = $model['eccSquared']; - $e2pr = $e2 / (1 - $e2); + $e2pr = $e2 / ( 1 - $e2 ); $radius = $model['maxAxis']; $v = $radius / sqrt( 1 - $e2 * $sin2Lat ); @@ -232,7 +231,7 @@ $a = ( $long - $longOrig ) * $cosLat; $m = $this->getMeridianDistance( $radius, $lat, $e2 ); - if ($latOrigin != 0) { + if ( $latOrigin != 0 ) { $m0 = $this->getMeridianDistance( $radius, $latOrig, $e2 ); } else { $m0 = 0.0; @@ -241,17 +240,17 @@ $utmArray['northing'] = $utmArray['northingOffset'] + $utmArray['scale'] * ( ( $m - $m0 ) + $v * $tanLat * ( $a * $a / 2 + ( 5 - $t + 9 * $c + 4 * $c * $c ) * pow( $a, 4 ) / 24 - + ( 61 - 58 * $t + $t * $t + 600 * $c - 330 * $e2pr) * pow( $a, 6 ) / 720 - )); + + ( 61 - 58 * $t + $t * $t + 600 * $c - 330 * $e2pr ) * pow( $a, 6 ) / 720 + ) ); - if ($this->lat < 0) { + if ( $this->lat < 0 ) { $utmArray['northing'] += $utmArray['northingOffsetSouth']; } $utmArray['easting'] = $utmArray['eastingOffset'] + $utmArray['scale'] * $v * ( $a + ( 1 - $t + $c ) * pow( $a, 3 ) / 6 - + (5 - 18 * $t + pow( $t, 2 ) + 72 * $c - 58 * $e2pr) * pow( $a, 5 ) / 120 + + ( 5 - 18 * $t + pow( $t, 2 ) + 72 * $c - 58 * $e2pr ) * pow( $a, 5 ) / 120 ); $utmArray['error'] = 0; @@ -308,7 +307,7 @@ # Code by [[wikipedia:de:Benutzer:Meleager]] protected function getCH1903( &$ch1903Array ) { # outside reasonable range - if ( $this->lat < 45.5 || $this->lat > 48 || $this->long < 5.0 || $this->long > 11) { + if ( $this->lat < 45.5 || $this->lat > 48 || $this->long < 5.0 || $this->long > 11 ) { return false; } diff --git a/composer.json b/composer.json index 686b65b..b8f68fb 100644 --- a/composer.json +++ b/composer.json @@ -1,11 +1,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..4ffde0b --- /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="UTF-8"/> + <exclude-pattern>vendor</exclude-pattern> + <exclude-pattern>node_modules</exclude-pattern> +</ruleset> -- To view, visit https://gerrit.wikimedia.org/r/356958 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I8c322b466ac8d40df52c80fa5a78153a592d5a98 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MapSources Gerrit-Branch: master Gerrit-Owner: Umherirrender <umherirrender_de...@web.de> Gerrit-Reviewer: Legoktm <lego...@member.fsf.org> Gerrit-Reviewer: Siebrand <siebr...@kitano.nl> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits