Skip to content
This repository was archived by the owner on Dec 15, 2020. It is now read-only.

Commit 35f0b8c

Browse files
authored
Merge pull request #64 from wmde/php55
Update to PHP 5.5 and short array syntax
2 parents b319656 + 4c0fffe commit 35f0b8c

File tree

11 files changed

+107
-112
lines changed

11 files changed

+107
-112
lines changed

.travis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ env:
44
- QUNIT=false
55

66
php:
7-
- 5.3
8-
- 5.4
97
- 5.5
108
- 5.6
119
- hhvm
1210

1311
matrix:
1412
include:
15-
- php: 5.3
13+
- php: 5.5
1614
env: QUNIT=true
1715

1816
before_script:

DataTypes.mw.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313
die( 'Not an entry point.' );
1414
}
1515

16-
$GLOBALS['wgExtensionCredits']['datavalues'][] = array(
16+
$GLOBALS['wgExtensionCredits']['datavalues'][] = [
1717
'path' => __DIR__,
1818
'name' => 'DataTypes',
1919
'version' => DataTypes_VERSION,
20-
'author' => array(
20+
'author' => [
2121
'The Wikidata team',
22-
),
22+
],
2323
'url' => 'https://github.com/wmde/DataTypes',
2424
'descriptionmsg' => 'datatypes-desc',
2525
'license-name' => 'GPL-2.0+'
26-
);
26+
];
2727

2828
$GLOBALS['wgMessagesDirs']['DataTypes'] = __DIR__ . '/i18n';
2929

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
"irc": "irc://irc.freenode.net/wikidata"
2424
},
2525
"require": {
26-
"php": ">=5.3.0"
26+
"php": ">=5.5.0"
2727
},
2828
"require-dev": {
29-
"mediawiki/mediawiki-codesniffer": "~0.5"
29+
"mediawiki/mediawiki-codesniffer": "~0.7"
3030
},
3131
"autoload": {
3232
"files" : [

js/resources.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,28 @@
1313
preg_match( '+' . preg_quote( DIRECTORY_SEPARATOR ) . '(?:vendor|extensions)'
1414
. preg_quote( DIRECTORY_SEPARATOR ) . '.*+', __DIR__, $remoteExtPath );
1515

16-
$moduleTemplate = array(
16+
$moduleTemplate = [
1717
'localBasePath' => __DIR__,
1818
'remoteExtPath' => '..' . $remoteExtPath[0],
19-
);
19+
];
2020

21-
return array(
22-
23-
'dataTypes.__namespace' => $moduleTemplate + array(
21+
return [
22+
'dataTypes.__namespace' => $moduleTemplate + [
2423
'scripts' => 'dataTypes/__namespace.js',
25-
),
24+
],
2625

27-
'dataTypes.DataType' => $moduleTemplate + array(
26+
'dataTypes.DataType' => $moduleTemplate + [
2827
'scripts' => 'dataTypes/DataType.js',
2928
'dependencies' => 'dataTypes.__namespace',
30-
),
29+
],
3130

32-
'dataTypes.DataTypeStore' => $moduleTemplate + array(
31+
'dataTypes.DataTypeStore' => $moduleTemplate + [
3332
'scripts' => 'dataTypes/DataTypeStore.js',
34-
'dependencies' => array(
33+
'dependencies' => [
3534
'dataTypes.__namespace',
3635
'dataTypes.DataType',
37-
),
38-
),
39-
);
36+
],
37+
],
38+
];
4039

4140
} );

phpcs.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<?xml version="1.0"?>
22
<ruleset name="DataValuesDataTypes">
33
<!-- See https://github.com/wikimedia/mediawiki-tools-codesniffer/blob/master/MediaWiki/ruleset.xml -->
4-
<rule ref="vendor/mediawiki/mediawiki-codesniffer/MediaWiki">
5-
<exclude name="Generic.Arrays.DisallowLongArraySyntax" />
6-
</rule>
4+
<rule ref="vendor/mediawiki/mediawiki-codesniffer/MediaWiki" />
75

86
<rule ref="Generic.ControlStructures" />
97
<rule ref="Generic.PHP.CharacterBeforePHPOpeningTag" />

src/DataType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ public function getMessageKey() {
8989
* @return string[]
9090
*/
9191
public function toArray() {
92-
return array(
92+
return [
9393
'dataValueType' => $this->dataValueType
94-
);
94+
];
9595
}
9696

9797
}

src/DataTypeFactory.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ class DataTypeFactory {
1818
*
1919
* @var DataType[]
2020
*/
21-
private $types = array();
21+
private $types = [];
2222

2323
/**
2424
* @var string[] Associative array mapping data type identifiers to data value type identifiers.
2525
*/
26-
private $valueTypes = array();
26+
private $valueTypes = [];
2727

2828
/**
2929
* @since 0.5
@@ -55,7 +55,7 @@ public function __construct( array $valueTypes ) {
5555
* @return self
5656
*/
5757
public static function newFromTypes( array $dataTypes ) {
58-
$factory = new self( array() );
58+
$factory = new self( [] );
5959

6060
foreach ( $dataTypes as $dataType ) {
6161
$factory->registerDataType( $dataType );
@@ -118,7 +118,7 @@ public function getType( $typeId ) {
118118
* @return DataType[]
119119
*/
120120
public function getTypes() {
121-
$types = array();
121+
$types = [];
122122

123123
foreach ( $this->getTypeIds() as $typeId ) {
124124
$types[$typeId] = $this->getType( $typeId );

src/Modules/DataTypesModule.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public function getDataTypeFactory() {
144144
*/
145145
public function getScript( ResourceLoaderContext $context ) {
146146
$configVarName = $this->getConfigVarName();
147-
$typesJson = array();
147+
$typesJson = [];
148148

149149
foreach ( $this->dataTypes as $dataType ) {
150150
$typesJson[ $dataType->getId() ] = $dataType->toArray();
@@ -162,7 +162,7 @@ public function getScript( ResourceLoaderContext $context ) {
162162
* @return string[]
163163
*/
164164
public function getMessages() {
165-
$messageKeys = array();
165+
$messageKeys = [];
166166

167167
foreach ( $this->dataTypes as $dataType ) {
168168
// TODO: currently we assume that the type is using a message while it does not have to.
@@ -184,9 +184,9 @@ public function getMessages() {
184184
public function getDefinitionSummary( ResourceLoaderContext $context ) {
185185
$summary = parent::getDefinitionSummary( $context );
186186

187-
$summary[] = array(
187+
$summary[] = [
188188
'dataHash' => sha1( json_encode( array_keys( $this->dataTypes ) ) )
189-
);
189+
];
190190

191191
return $summary;
192192
}

tests/Modules/DataTypesModuleTest.php

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,26 @@ class DataTypesModuleTest extends \PHPUnit_Framework_TestCase {
2121
* @return array [instance, resource definition]
2222
*/
2323
public function provideDataTypesModuleAndResourceDefinition() {
24-
$dataTypeFactory = new DataTypeFactory( array( 'url' => 'string' ) );
24+
$dataTypeFactory = new DataTypeFactory( [ 'url' => 'string' ] );
2525

26-
$validResourceDefinitions = array(
27-
array(
26+
$validResourceDefinitions = [
27+
[
2828
'datatypesconfigvarname' => 'foo',
2929
'datatypefactory' => function() {
30-
return new DataTypeFactory( array() );
30+
return new DataTypeFactory( [] );
3131
}
32-
),
33-
array(
32+
],
33+
[
3434
'datatypesconfigvarname' => 'bar123',
3535
'datatypefactory' => $dataTypeFactory
36-
)
37-
);
36+
],
37+
];
3838

39-
$cases = array();
39+
$cases = [];
4040

4141
foreach ( $validResourceDefinitions as $definition ) {
4242
$instance = new DataTypesModule( $definition );
43-
$cases[] = array( $instance, $definition );
43+
$cases[] = [ $instance, $definition ];
4444
}
4545

4646
return $cases;
@@ -62,53 +62,53 @@ public function testGetDataTypeFactory( DataTypesModule $module ) {
6262
* @return array [invalid resource definition, case description]
6363
*/
6464
public function provideInvalidResourceDefinition() {
65-
$dataTypeFactory = new DataTypeFactory( array() );
65+
$dataTypeFactory = new DataTypeFactory( [] );
6666

67-
$validDefinition = array(
67+
$validDefinition = [
6868
'datatypesconfigvarname' => 'foo',
6969
'datatypefactory' => function() {
70-
return new DataTypeFactory( array() );
70+
return new DataTypeFactory( [] );
7171
}
72-
);
72+
];
7373

74-
return array(
75-
array(
76-
array(
74+
return [
75+
[
76+
[
7777
'datatypesconfigvarname' => 'foo'
78-
),
78+
],
7979
'missing "datatypefactory" field'
80-
),
81-
array(
82-
array(
80+
],
81+
[
82+
[
8383
'datatypefactory' => $dataTypeFactory
84-
),
84+
],
8585
'missing "datatypesconfigvarname" field'
86-
),
87-
array(
88-
array(),
86+
],
87+
[
88+
[],
8989
'all fields missing'
90-
),
91-
array(
90+
],
91+
[
9292
array_merge(
9393
$validDefinition,
94-
array(
94+
[
9595
'datatypefactory' => 123
96-
)
96+
]
9797
),
9898
'"datatypefactory" field has value of wrong type'
99-
),
100-
array(
99+
],
100+
[
101101
array_merge(
102102
$validDefinition,
103-
array(
103+
[
104104
'datatypefactory' => function() {
105105
return null;
106106
}
107-
)
107+
]
108108
),
109109
'"datatypefactory" callback does not return a DataTypeFactory instance'
110-
)
111-
);
110+
],
111+
];
112112
}
113113

114114
/**
@@ -143,7 +143,7 @@ public function testConstructorErrors( array $definition, $caseDescription ) {
143143

144144
public function testGetDefinitionSummary() {
145145
$definition = $this->makeDefinition(
146-
array( 'foo' => 'string' )
146+
[ 'foo' => 'string' ]
147147
);
148148

149149
$module = new DataTypesModule( $definition );
@@ -155,14 +155,14 @@ public function testGetDefinitionSummary() {
155155
}
156156

157157
public function testGetDefinitionSummary_notEqualForDifferentDataTypes() {
158-
$definition1 = $this->makeDefinition( array(
158+
$definition1 = $this->makeDefinition( [
159159
'foo' => 'string'
160-
) );
160+
] );
161161

162-
$definition2 = $this->makeDefinition( array(
162+
$definition2 = $this->makeDefinition( [
163163
'foo' => 'string',
164164
'bar' => 'string'
165-
) );
165+
] );
166166

167167
$module1 = new DataTypesModule( $definition1 );
168168
$module2 = new DataTypesModule( $definition2 );
@@ -176,10 +176,10 @@ public function testGetDefinitionSummary_notEqualForDifferentDataTypes() {
176176
}
177177

178178
private function makeDefinition( array $dataTypes ) {
179-
return array(
179+
return [
180180
'datatypesconfigvarname' => 'foo123',
181181
'datatypefactory' => new DataTypeFactory( $dataTypes )
182-
);
182+
];
183183
}
184184

185185
/**

0 commit comments

Comments
 (0)