Skip to content

Commit

Permalink
Upgrade mediawiki-codesniffer to latest version (45.0.0)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
codders committed Dec 6, 2024
1 parent 628018f commit 314e20b
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 13 deletions.
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"require-dev": {
"phpunit/phpunit": "~8.0",
"ockcyp/covers-validator": "^1.3.3",
"mediawiki/mediawiki-codesniffer": "^34"
"mediawiki/mediawiki-codesniffer": "45.0.0"
},
"extra": {
"branch-alias": {
Expand Down Expand Up @@ -67,5 +67,10 @@
"@cs",
"@test"
]
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
1 change: 1 addition & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
<exclude name="Generic.Files.LineLength.TooLong" />
<exclude name="Generic.Files.LineLength.MaxExceeded" />
</rule>
<rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki"/>
</ruleset>
2 changes: 1 addition & 1 deletion src/DataValues/MonolingualTextValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function unserialize( $value ) {
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(
$expectedValueType,
$dataValueType,
$message = '',
Exception $previous = null
?Exception $previous = null
) {
$this->expectedValueType = $expectedValueType;
$this->dataValueType = $dataValueType;
Expand Down
4 changes: 4 additions & 0 deletions src/ValueParsers/BoolParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class BoolParser extends StringValueParser {

private const FORMAT_NAME = 'bool';

/**
* @var Mapping from possible string values to their
* boolean equivalents
*/
private static $values = [
'yes' => true,
'on' => true,
Expand Down
2 changes: 1 addition & 1 deletion src/ValueParsers/StringParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class StringParser implements ValueParser {
/**
* @param StringNormalizer|null $normalizer
*/
public function __construct( StringNormalizer $normalizer = null ) {
public function __construct( ?StringNormalizer $normalizer = null ) {
$this->normalizer = $normalizer ?: new NullStringNormalizer();
}

Expand Down
2 changes: 1 addition & 1 deletion src/ValueParsers/StringValueParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract class StringValueParser implements ValueParser {
/**
* @param ParserOptions|null $options
*/
public function __construct( ParserOptions $options = null ) {
public function __construct( ?ParserOptions $options = null ) {
$this->options = $options ?: new ParserOptions();

$this->defaultOption( ValueParser::OPT_LANG, 'en' );
Expand Down
6 changes: 3 additions & 3 deletions tests/ValueParsers/DispatchingValueParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@
*/
class DispatchingValueParserTest extends TestCase {

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

$mock->expects( $invocation )
->method( 'parse' )
->will( $this->returnCallback( function( $value ) {
->willReturnCallback( static function ( $value ) {
if ( $value === 'invalid' ) {
throw new ParseException( 'failed' );
}
return $value;
} ) );
} );

return $mock;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ValueParsers/NullParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function invalidInputProvider() {
*
* @dataProvider invalidInputProvider
*/
public function testParseWithInvalidInputs( $value, ValueParser $parser = null ) {
public function testParseWithInvalidInputs( $value, ?ValueParser $parser = null ) {
$this->markTestSkipped( 'NullParser has no invalid inputs' );
}

Expand Down
4 changes: 2 additions & 2 deletions tests/ValueParsers/StringParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public function provideParse() {
$normalizer = $this->createMock( StringNormalizer::class );
$normalizer->expects( $this->once() )
->method( 'normalize' )
->will( $this->returnCallback( function( $value ) {
->willReturnCallback( static function ( $value ) {
return strtolower( trim( $value ) );
} ) );
} );

return [
'simple' => [ 'hello world', null, new StringValue( 'hello world' ) ],
Expand Down
4 changes: 2 additions & 2 deletions tests/ValueParsers/ValueParserTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ abstract protected function getInstance();
* @param mixed $expected
* @param ValueParser|null $parser
*/
public function testParseWithValidInputs( $value, $expected, ValueParser $parser = null ) {
public function testParseWithValidInputs( $value, $expected, ?ValueParser $parser = null ) {
if ( $parser === null ) {
$parser = $this->getInstance();
}
Expand Down Expand Up @@ -77,7 +77,7 @@ private function assertSmartEquals( $expected, $actual ) {
* @param mixed $value
* @param ValueParser|null $parser
*/
public function testParseWithInvalidInputs( $value, ValueParser $parser = null ) {
public function testParseWithInvalidInputs( $value, ?ValueParser $parser = null ) {
if ( $parser === null ) {
$parser = $this->getInstance();
}
Expand Down

0 comments on commit 314e20b

Please sign in to comment.