Skip to content

Commit 6d6c442

Browse files
kghblnmwjames
authored andcommitted
Convert code to use PHP 5.4+ short array syntax (#28)
1 parent 4dcb3fe commit 6d6c442

9 files changed

+100
-100
lines changed

SemanticCompoundQueries.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,18 @@ public static function initExtension() {
5959
define( 'SCQ_VERSION', '1.1.0-alpha' );
6060

6161
// Register the extension
62-
$GLOBALS['wgExtensionCredits']['semantic'][] = array(
62+
$GLOBALS['wgExtensionCredits']['semantic'][] = [
6363
'path' => __FILE__,
6464
'name' => 'Semantic Compound Queries',
6565
'version' => SCQ_VERSION,
66-
'author' => array(
66+
'author' => [
6767
'[https://www.semantic-mediawiki.org/ Semantic MediaWiki project]',
6868
'Yaron Koren'
69-
),
69+
],
7070
'url' => 'https://www.mediawiki.org/wiki/Extension:Semantic_Compound_Queries',
7171
'descriptionmsg' => 'semanticcompoundqueries-desc',
7272
'license-name' => 'GPL-2.0+'
73-
);
73+
];
7474

7575
// Register message files
7676
$GLOBALS['wgMessagesDirs']['SemanticCompoundQueries'] = __DIR__ . '/i18n';
@@ -109,7 +109,7 @@ public static function onExtensionFunction() {
109109
$GLOBALS['wgAPIModules']['compoundquery'] = 'SCQ\Api\CompoundQuery';
110110

111111
$GLOBALS['wgHooks']['ParserFirstCallInit'][] = function( Parser &$parser ) {
112-
$parser->setFunctionHook( 'compound_query', array( '\SCQ\CompoundQueryProcessor', 'doCompoundQuery' ) );
112+
$parser->setFunctionHook( 'compound_query', [ '\SCQ\CompoundQueryProcessor', 'doCompoundQuery' ] );
113113

114114
// always return true, in order not to stop MW's hook processing!
115115
return true;

i18n/SemanticCompoundQueries.i18n.magic.php

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,74 +3,74 @@
33
*
44
*/
55

6-
$magicWords = array();
6+
$magicWords = [];
77

88
/** English (English) */
9-
$magicWords['en'] = array(
10-
'compound_query' => array( 0, 'compound_query' ),
11-
);
9+
$magicWords['en'] = [
10+
'compound_query' => [ 0, 'compound_query' ],
11+
];
1212

1313
/** Arabic (العربية) */
14-
$magicWords['ar'] = array(
15-
'compound_query' => array( 0, 'استعلام_مركب' ),
16-
);
14+
$magicWords['ar'] = [
15+
'compound_query' => [ 0, 'استعلام_مركب' ],
16+
];
1717

1818
/** Egyptian Arabic (مصرى) */
19-
$magicWords['arz'] = array(
20-
'compound_query' => array( 0, 'استعلام_مركب' ),
21-
);
19+
$magicWords['arz'] = [
20+
'compound_query' => [ 0, 'استعلام_مركب' ],
21+
];
2222

2323
/** Chuvash (Чӑвашла) */
24-
$magicWords['cv'] = array(
25-
'compound_query' => array( 0, 'compound_query' ),
26-
);
24+
$magicWords['cv'] = [
25+
'compound_query' => [ 0, 'compound_query' ],
26+
];
2727

2828
/** German (Deutsch) */
29-
$magicWords['de'] = array(
30-
'compound_query' => array( 0, 'abfrage_zusammen', 'frage_zusammen' ),
31-
);
29+
$magicWords['de'] = [
30+
'compound_query' => [ 0, 'abfrage_zusammen', 'frage_zusammen' ],
31+
];
3232

3333
/** Japanese (日本語) */
34-
$magicWords['ja'] = array(
35-
'compound_query' => array( 0, '複合クエリ', '複合クエリー' ),
36-
);
34+
$magicWords['ja'] = [
35+
'compound_query' => [ 0, '複合クエリ', '複合クエリー' ],
36+
];
3737

3838
/** Korean (한국어) */
39-
$magicWords['ko'] = array(
40-
'compound_query' => array( 0, '복합_쿼리' ),
41-
);
39+
$magicWords['ko'] = [
40+
'compound_query' => [ 0, '복합_쿼리' ],
41+
];
4242

4343
/** Macedonian (македонски) */
44-
$magicWords['mk'] = array(
45-
'compound_query' => array( 0, 'мешовито_барање' ),
46-
);
44+
$magicWords['mk'] = [
45+
'compound_query' => [ 0, 'мешовито_барање' ],
46+
];
4747

4848
/** Low Saxon (Netherlands) (Nedersaksies) */
49-
$magicWords['nds-nl'] = array(
50-
'compound_query' => array( 0, 'samenestelden_zeukopdrachte', 'samengestelde_zoekopdracht' ),
51-
);
49+
$magicWords['nds-nl'] = [
50+
'compound_query' => [ 0, 'samenestelden_zeukopdrachte', 'samengestelde_zoekopdracht' ],
51+
];
5252

5353
/** Dutch (Nederlands) */
54-
$magicWords['nl'] = array(
55-
'compound_query' => array( 0, 'samengestelde_zoekopdracht' ),
56-
);
54+
$magicWords['nl'] = [
55+
'compound_query' => [ 0, 'samengestelde_zoekopdracht' ],
56+
];
5757

5858
/** Brazilian Portuguese (português do Brasil) */
59-
$magicWords['pt-br'] = array(
60-
'compound_query' => array( 0, 'consulta_composta' ),
61-
);
59+
$magicWords['pt-br'] = [
60+
'compound_query' => [ 0, 'consulta_composta' ],
61+
];
6262

6363
/** Serbian (Latin script) (srpski (latinica)‎) */
64-
$magicWords['sr-el'] = array(
65-
'compound_query' => array( 0, 'sastavi_upit' ),
66-
);
64+
$magicWords['sr-el'] = [
65+
'compound_query' => [ 0, 'sastavi_upit' ],
66+
];
6767

6868
/** Simplified Chinese (中文(简体)‎) */
69-
$magicWords['zh-hans'] = array(
70-
'compound_query' => array( 0, '组合查询' ),
71-
);
69+
$magicWords['zh-hans'] = [
70+
'compound_query' => [ 0, '组合查询' ],
71+
];
7272

7373
/** Traditional Chinese (中文(繁體)‎) */
74-
$magicWords['zh-hant'] = array(
75-
'compound_query' => array( 0, '組合搜尋' ),
76-
);
74+
$magicWords['zh-hant'] = [
75+
'compound_query' => [ 0, '組合搜尋' ],
76+
];

src/Api/CompoundQuery.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ public function execute() {
4242
* @return array
4343
*/
4444
public function getAllowedParams() {
45-
return array(
46-
'query' => array(
45+
return [
46+
'query' => [
4747
ApiBase::PARAM_TYPE => 'string',
4848
ApiBase::PARAM_REQUIRED => true,
49-
),
50-
);
49+
],
50+
];
5151
}
5252

5353
/**
@@ -57,9 +57,9 @@ public function getAllowedParams() {
5757
* @return array
5858
*/
5959
public function getParamDescription() {
60-
return array(
60+
return [
6161
'query' => 'The multiple queries string in ask-language'
62-
);
62+
];
6363
}
6464

6565
/**
@@ -69,9 +69,9 @@ public function getParamDescription() {
6969
* @return array
7070
*/
7171
public function getDescription() {
72-
return array(
72+
return [
7373
'API module to query SMW by providing a multiple queries in the ask language.'
74-
);
74+
];
7575
}
7676

7777
/**
@@ -81,10 +81,10 @@ public function getDescription() {
8181
* @return array
8282
*/
8383
protected function getExamples() {
84-
return array(
84+
return [
8585
'api.php?action=compoundquery&query=' . urlencode( '[[Has city::Vienna]]; ?Has coordinates|[[Has city::Graz]]; ?Has coordinates' ),
8686
'api.php?action=compoundquery&query=' . urlencode( '|[[Has city::Vienna]]; ?Has coordinates|[[Has city::Graz]]; ?Has coordinates' ),
87-
);
87+
];
8888
}
8989

9090
/**

src/CompoundQueryProcessor.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static function doCompoundQuery( Parser &$parser ) {
4141
global $smwgQEnabled, $smwgIQRunningNumber;
4242

4343
if ( !$smwgQEnabled ) {
44-
return smwfEncodeMessages( array( wfMessage( 'smw_iq_disabled' )->inContentLanguage()->text() ) );
44+
return smwfEncodeMessages( [ wfMessage( 'smw_iq_disabled' )->inContentLanguage()->text() ] );
4545
}
4646

4747
$smwgIQRunningNumber++;
@@ -66,8 +66,8 @@ public static function doCompoundQuery( Parser &$parser ) {
6666
* @return array
6767
*/
6868
public static function separateParams( $params ) {
69-
$queryParams = array();
70-
$otherParams = array();
69+
$queryParams = [];
70+
$otherParams = [];
7171

7272
foreach ( $params as $param ) {
7373
// Very primitive heuristic - if the parameter
@@ -83,7 +83,7 @@ public static function separateParams( $params ) {
8383
}
8484
}
8585
}
86-
return array( $queryParams, $otherParams );
86+
return [ $queryParams, $otherParams ];
8787
}
8888

8989
/**
@@ -94,8 +94,8 @@ public static function separateParams( $params ) {
9494
* @return array
9595
*/
9696
public static function queryAndMergeResults( $queryParams, $otherParams ) {
97-
$results = array();
98-
$printRequests = array();
97+
$results = [];
98+
$printRequests = [];
9999

100100
foreach ( $queryParams as $param ) {
101101
$subQueryParams = self::getSubParams( $param );
@@ -112,7 +112,7 @@ public static function queryAndMergeResults( $queryParams, $otherParams ) {
112112

113113
// Sort results so that they'll show up by page name
114114
if( !isset($otherParams['unsorted']) || !strcmp( $otherParams['unsorted'], 'on' ) ) {
115-
uasort( $results, array( '\SCQ\CompoundQueryProcessor', 'compareQueryResults' ) );
115+
uasort( $results, [ '\SCQ\CompoundQueryProcessor', 'compareQueryResults' ] );
116116
}
117117

118118
$queryResult = new CompoundQueryResult( $printRequests, new Query(), $results, smwfGetStore() );
@@ -122,7 +122,7 @@ public static function queryAndMergeResults( $queryParams, $otherParams ) {
122122
$otherParams = self::getProcessedParams( $otherParams, $printRequests );
123123
}
124124

125-
return array( $queryResult, $otherParams );
125+
return [ $queryResult, $otherParams ];
126126
}
127127

128128
/**
@@ -135,7 +135,7 @@ public static function queryAndMergeResults( $queryParams, $otherParams ) {
135135
* @return array
136136
*/
137137
protected static function getSubParams( $param ) {
138-
$sub_params = array();
138+
$sub_params = [];
139139
$sub_param = '';
140140
$uncompleted_square_brackets = 0;
141141

@@ -171,7 +171,7 @@ protected static function getSubParams( $param ) {
171171
* @return SMWQueryResult
172172
*/
173173
protected static function getQueryResultFromFunctionParams( $rawparams, $context = QueryProcessor::INLINE_QUERY, $showmode = false ) {
174-
$printouts = array();
174+
$printouts = [];
175175
self::processFunctionParams( $rawparams, $querystring, $params, $printouts, $showmode );
176176
return self::getQueryResultFromQueryString( $querystring, $params, $printouts, $context );
177177
}
@@ -189,7 +189,7 @@ protected static function mergeSMWQueryResults( $result1, $result2 ) {
189189
return $result2;
190190
}
191191

192-
$existing_page_names = array();
192+
$existing_page_names = [];
193193
foreach ( $result1 as $r1 ) {
194194
$existing_page_names[] = $r1->getSerialization();
195195
}
@@ -205,7 +205,7 @@ protected static function mergeSMWQueryResults( $result1, $result2 ) {
205205
}
206206

207207
protected static function mergeSMWPrintRequests( $printRequests1, $printRequests2 ) {
208-
$existingPrintoutLabels = array();
208+
$existingPrintoutLabels = [];
209209
foreach ( $printRequests1 as $p1 ) {
210210
$existingPrintoutLabels[] = $p1->getLabel();
211211
}
@@ -238,7 +238,7 @@ protected static function getQueryResultFromQueryString( $querystring, array $pa
238238
$query = self::createQuery( $querystring, $params, $context, null, $extraPrintouts );
239239
$queryResult = smwfGetStore()->getQueryResult( $query );
240240

241-
$parameters = array();
241+
$parameters = [];
242242

243243
if ( version_compare( SMW_VERSION, '1.7.2', '>' ) ) {
244244
foreach ( $params as $param ) {

src/CompoundQueryResult.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class CompoundQueryResult extends QueryResult {
2424
* @param QueryResult $newResult
2525
*/
2626
public function addResult( QueryResult $newResult ) {
27-
$existingPageNames = array();
27+
$existingPageNames = [];
2828

2929
while ( $row = $this->getNext() ) {
3030
if ( $row[0] instanceof ResultArray ) {

tests/phpunit/Integration/I18nJsonFileIntegrityTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ public function testI18NJsonDecodeEncode( $file ) {
3434

3535
public function i18nFileProvider() {
3636

37-
$provider = array();
37+
$provider = [];
3838
$location = $GLOBALS['wgMessagesDirs']['SemanticCompoundQueries'];
3939

4040
$bulkFileProvider = UtilityFactory::getInstance()->newBulkFileProvider( $location );
4141
$bulkFileProvider->searchByFileExtension( 'json' );
4242

4343
foreach ( $bulkFileProvider->getFiles() as $file ) {
44-
$provider[] = array( $file );
44+
$provider[] = [ $file ];
4545
}
4646

4747
return $provider;

0 commit comments

Comments
 (0)