Skip to content

Commit a7284df

Browse files
committed
Upgrade mediawiki-codesniffer to latest version (45.0.0)
This repository is currently using version 34 of the Mediawiki coding style phpcs rules. If the code aims to comply with Mediawiki style guidelines, it makes sense that it continues to comply at current versions of the rules. Besides being simply different, the newer versions of the rules introduce, for example, MediaWiki.Usage.NullableType.ExplicitNullableTypes, which enforces compliance with coming deprecation rules in PHP 8.4 concerning nullable types. If the code does not remove the soon-to-be-deprecated form of nullable type declarations, the library will no longer be usable in Mediawiki for PHP 8.4 deployments. Resolves #100 Bug: T379481
1 parent 628018f commit a7284df

File tree

11 files changed

+24
-13
lines changed

11 files changed

+24
-13
lines changed

composer.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"require-dev": {
3131
"phpunit/phpunit": "~8.0",
3232
"ockcyp/covers-validator": "^1.3.3",
33-
"mediawiki/mediawiki-codesniffer": "^34"
33+
"mediawiki/mediawiki-codesniffer": "45.0.0"
3434
},
3535
"extra": {
3636
"branch-alias": {
@@ -67,5 +67,10 @@
6767
"@cs",
6868
"@test"
6969
]
70+
},
71+
"config": {
72+
"allow-plugins": {
73+
"dealerdirect/phpcodesniffer-composer-installer": true
74+
}
7075
}
7176
}

phpcs.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@
77
<exclude name="Generic.Files.LineLength.TooLong" />
88
<exclude name="Generic.Files.LineLength.MaxExceeded" />
99
</rule>
10+
<rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki"/>
11+
<arg name="bootstrap" value="./vendor/mediawiki/mediawiki-codesniffer/utils/bootstrap-ci.php"/>
1012
</ruleset>

src/DataValues/MonolingualTextValue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function unserialize( $value ) {
6565
}
6666

6767
public function __unserialize( array $data ): void {
68-
list( $languageCode, $text ) = $data;
68+
[ $languageCode, $text ] = $data;
6969
$this->__construct( $languageCode, $text );
7070
}
7171

src/ValueFormatters/Exceptions/MismatchingDataValueTypeException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(
3636
$expectedValueType,
3737
$dataValueType,
3838
$message = '',
39-
Exception $previous = null
39+
?Exception $previous = null
4040
) {
4141
$this->expectedValueType = $expectedValueType;
4242
$this->dataValueType = $dataValueType;

src/ValueParsers/BoolParser.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ class BoolParser extends StringValueParser {
1818

1919
private const FORMAT_NAME = 'bool';
2020

21+
/**
22+
* @var Mapping from possible string values to their
23+
* boolean equivalents
24+
*/
2125
private static $values = [
2226
'yes' => true,
2327
'on' => true,

src/ValueParsers/StringParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class StringParser implements ValueParser {
2626
/**
2727
* @param StringNormalizer|null $normalizer
2828
*/
29-
public function __construct( StringNormalizer $normalizer = null ) {
29+
public function __construct( ?StringNormalizer $normalizer = null ) {
3030
$this->normalizer = $normalizer ?: new NullStringNormalizer();
3131
}
3232

src/ValueParsers/StringValueParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ abstract class StringValueParser implements ValueParser {
2828
/**
2929
* @param ParserOptions|null $options
3030
*/
31-
public function __construct( ParserOptions $options = null ) {
31+
public function __construct( ?ParserOptions $options = null ) {
3232
$this->options = $options ?: new ParserOptions();
3333

3434
$this->defaultOption( ValueParser::OPT_LANG, 'en' );

tests/ValueParsers/DispatchingValueParserTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@
2222
*/
2323
class DispatchingValueParserTest extends TestCase {
2424

25-
private function getParser( $invocation ) : ValueParser {
25+
private function getParser( $invocation ): ValueParser {
2626
$mock = $this->createMock( ValueParser::class );
2727

2828
$mock->expects( $invocation )
2929
->method( 'parse' )
30-
->will( $this->returnCallback( function( $value ) {
30+
->willReturnCallback( static function ( $value ) {
3131
if ( $value === 'invalid' ) {
3232
throw new ParseException( 'failed' );
3333
}
3434
return $value;
35-
} ) );
35+
} );
3636

3737
return $mock;
3838
}

tests/ValueParsers/NullParserTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function invalidInputProvider() {
5555
*
5656
* @dataProvider invalidInputProvider
5757
*/
58-
public function testParseWithInvalidInputs( $value, ValueParser $parser = null ) {
58+
public function testParseWithInvalidInputs( $value, ?ValueParser $parser = null ) {
5959
$this->markTestSkipped( 'NullParser has no invalid inputs' );
6060
}
6161

tests/ValueParsers/StringParserTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ public function provideParse() {
2626
$normalizer = $this->createMock( StringNormalizer::class );
2727
$normalizer->expects( $this->once() )
2828
->method( 'normalize' )
29-
->will( $this->returnCallback( function( $value ) {
29+
->willReturnCallback( static function ( $value ) {
3030
return strtolower( trim( $value ) );
31-
} ) );
31+
} );
3232

3333
return [
3434
'simple' => [ 'hello world', null, new StringValue( 'hello world' ) ],

0 commit comments

Comments
 (0)