From 06415a03d13e35ea471630ec6fa0f1f44cd45053 Mon Sep 17 00:00:00 2001 From: Arthur Taylor Date: Fri, 6 Dec 2024 14:07:02 +0100 Subject: [PATCH 1/7] 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 --- .github/workflows/php.yml | 2 -- composer.json | 9 +++++++-- phpcs.xml | 1 + src/DataValues/MonolingualTextValue.php | 2 +- .../Exceptions/MismatchingDataValueTypeException.php | 2 +- src/ValueParsers/BoolParser.php | 4 ++++ src/ValueParsers/StringParser.php | 2 +- src/ValueParsers/StringValueParser.php | 2 +- tests/ValueParsers/DispatchingValueParserTest.php | 6 +++--- tests/ValueParsers/NullParserTest.php | 2 +- tests/ValueParsers/StringParserTest.php | 4 ++-- tests/ValueParsers/ValueParserTestBase.php | 4 ++-- 12 files changed, 24 insertions(+), 16 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 3b16ee3..641f7c7 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -13,8 +13,6 @@ jobs: fail-fast: false matrix: php: - - '7.2' - - '7.3' - '7.4' steps: diff --git a/composer.json b/composer.json index e7f7d6c..6e51d8f 100644 --- a/composer.json +++ b/composer.json @@ -23,14 +23,14 @@ "irc": "irc://irc.freenode.net/wikidata" }, "require": { - "php": ">=7.2.0", + "php": ">=7.4", "data-values/data-values": "~3.0|~2.0|~1.0|~0.1", "data-values/interfaces": "~1.0|~0.2.0" }, "require-dev": { "phpunit/phpunit": "~8.0", "ockcyp/covers-validator": "^1.3.3", - "mediawiki/mediawiki-codesniffer": "^34" + "mediawiki/mediawiki-codesniffer": "^45" }, "extra": { "branch-alias": { @@ -67,5 +67,10 @@ "@cs", "@test" ] + }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } } } diff --git a/phpcs.xml b/phpcs.xml index 8649f80..52b4a07 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -7,4 +7,5 @@ + diff --git a/src/DataValues/MonolingualTextValue.php b/src/DataValues/MonolingualTextValue.php index 03eb876..e331064 100644 --- a/src/DataValues/MonolingualTextValue.php +++ b/src/DataValues/MonolingualTextValue.php @@ -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 ); } diff --git a/src/ValueFormatters/Exceptions/MismatchingDataValueTypeException.php b/src/ValueFormatters/Exceptions/MismatchingDataValueTypeException.php index 549c79d..1c25dec 100644 --- a/src/ValueFormatters/Exceptions/MismatchingDataValueTypeException.php +++ b/src/ValueFormatters/Exceptions/MismatchingDataValueTypeException.php @@ -36,7 +36,7 @@ public function __construct( $expectedValueType, $dataValueType, $message = '', - Exception $previous = null + ?Exception $previous = null ) { $this->expectedValueType = $expectedValueType; $this->dataValueType = $dataValueType; diff --git a/src/ValueParsers/BoolParser.php b/src/ValueParsers/BoolParser.php index 5583073..99faf7f 100644 --- a/src/ValueParsers/BoolParser.php +++ b/src/ValueParsers/BoolParser.php @@ -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, diff --git a/src/ValueParsers/StringParser.php b/src/ValueParsers/StringParser.php index 3efb4bf..4827694 100644 --- a/src/ValueParsers/StringParser.php +++ b/src/ValueParsers/StringParser.php @@ -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(); } diff --git a/src/ValueParsers/StringValueParser.php b/src/ValueParsers/StringValueParser.php index c80e3c3..ac638c0 100644 --- a/src/ValueParsers/StringValueParser.php +++ b/src/ValueParsers/StringValueParser.php @@ -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' ); diff --git a/tests/ValueParsers/DispatchingValueParserTest.php b/tests/ValueParsers/DispatchingValueParserTest.php index 0a547a7..7d42056 100644 --- a/tests/ValueParsers/DispatchingValueParserTest.php +++ b/tests/ValueParsers/DispatchingValueParserTest.php @@ -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; } diff --git a/tests/ValueParsers/NullParserTest.php b/tests/ValueParsers/NullParserTest.php index 68a2af5..1f1573e 100644 --- a/tests/ValueParsers/NullParserTest.php +++ b/tests/ValueParsers/NullParserTest.php @@ -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' ); } diff --git a/tests/ValueParsers/StringParserTest.php b/tests/ValueParsers/StringParserTest.php index 410f2d4..c707846 100644 --- a/tests/ValueParsers/StringParserTest.php +++ b/tests/ValueParsers/StringParserTest.php @@ -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' ) ], diff --git a/tests/ValueParsers/ValueParserTestBase.php b/tests/ValueParsers/ValueParserTestBase.php index 6e57c32..cf5fdd9 100644 --- a/tests/ValueParsers/ValueParserTestBase.php +++ b/tests/ValueParsers/ValueParserTestBase.php @@ -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(); } @@ -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(); } From b3114dcc9da1bc37cc6b0cd66137f951d17c0ee7 Mon Sep 17 00:00:00 2001 From: Jeroen De Dauw Date: Fri, 6 Dec 2024 17:11:44 +0100 Subject: [PATCH 2/7] Test with modern PHP --- .github/workflows/php.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 641f7c7..41cef68 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -14,6 +14,11 @@ jobs: matrix: php: - '7.4' + - '8.0' + - '8.1' + - '8.2' + - '8.3' + - '8.4' steps: - uses: actions/checkout@v2 From 9799074609af63d76b29f582d8f34e6f24b51bf1 Mon Sep 17 00:00:00 2001 From: Arthur Taylor Date: Mon, 9 Dec 2024 11:18:27 +0100 Subject: [PATCH 3/7] Bump version to 1.2.0 * Drop support for PHP 7.2, 7.3 * Upgrade codesniffer rules to current `mediawiki/mediawiki-codesniffer` version (45.0.0) * Make nullable type parameter declarations explicit for compatibility with PHP 8.4 * Start testing with modern versions of PHP (8.1-8.4) --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index de4bb6d..dc2ce75 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,13 @@ employees for the [Wikidata project](https://wikidata.org/). ## Release notes +### 1.2.0 (2024-12-10) + +* Drop support for PHP 7.2, 7.3 +* Upgrade codesniffer rules to current `mediawiki/mediawiki-codesniffer` version (45.0.0) +* Make nullable type parameter declarations explicit for compatibility with PHP 8.4 +* Start testing with modern versions of PHP (8.1-8.4) + ### 1.1.0 (2022-10-21) * Improved compatibility with PHP 8.1; From b21c2bd3b213d6233a645003df4f88956afc52f4 Mon Sep 17 00:00:00 2001 From: Jeroen De Dauw Date: Mon, 9 Dec 2024 23:42:56 +0100 Subject: [PATCH 4/7] Improve release notes --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index dc2ce75..0e9172e 100644 --- a/README.md +++ b/README.md @@ -56,10 +56,10 @@ employees for the [Wikidata project](https://wikidata.org/). ### 1.2.0 (2024-12-10) -* Drop support for PHP 7.2, 7.3 -* Upgrade codesniffer rules to current `mediawiki/mediawiki-codesniffer` version (45.0.0) -* Make nullable type parameter declarations explicit for compatibility with PHP 8.4 -* Start testing with modern versions of PHP (8.1-8.4) +* Dropped support for PHP 7.2 and PHP 7.3 +* Improved support for PHP 8.4 by explicitly declaring nullable types +* Upgraded codesniffer rules to current `mediawiki/mediawiki-codesniffer` version (45.0.0) +* Added testing with PHP 8.1 up to 8.4 ### 1.1.0 (2022-10-21) From 7a1c1037729462cd536eaed1236eb31cff4c5820 Mon Sep 17 00:00:00 2001 From: Jeroen De Dauw Date: Tue, 10 Dec 2024 00:16:25 +0100 Subject: [PATCH 5/7] Fix badges --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0e9172e..f0d5acd 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,16 @@ # DataValues Common -DataValues Common is a small library build on top of DataValues that provides common -implementations of the DataValues, ValueParsers, ValueFormatters and ValueValidators interfaces. +DataValues Common is a small library built on top of DataValues that provides common +implementations of the DataValues, ValueParsers, ValueFormatters, and ValueValidators interfaces. It is part of the [DataValues set of libraries](https://github.com/DataValues). -[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/DataValues/Common/PHP%20Composer)](https://github.com/DataValues/Common/actions?query=workflow%3A"PHP+Composer") -[![Code Coverage](https://scrutinizer-ci.com/g/DataValues/Common/badges/coverage.png?s=728b9287ebdd13fbe15255d4d55575c5b5d47b8f)](https://scrutinizer-ci.com/g/DataValues/Common/) +[![Build Status](https://img.shields.io/github/actions/workflow/status/DataValues/Common/php.yml?branch=master)](https://github.com/DataValues/Common/actions/workflows/php.yml?query=workflow%3APHP) +[![Code Coverage](https://scrutinizer-ci.com/g/DataValues/Common/badges/coverage.png?s=6432d29bf3fed068995e66093ad52e053099a916)](https://scrutinizer-ci.com/g/DataValues/Common/) On [Packagist](https://packagist.org/packages/data-values/common): -[![Latest Stable Version](https://poser.pugx.org/data-values/common/version.png)](https://packagist.org/packages/data-values/common) -[![Download count](https://poser.pugx.org/data-values/common/d/total.png)](https://packagist.org/packages/data-values/common) +[![Latest Stable Version](https://poser.pugx.org/data-values/common/v/stable)](https://packagist.org/packages/data-values/common) +[![Download count](https://poser.pugx.org/data-values/common/downloads)](https://packagist.org/packages/data-values/common) ## Installation From c586bd6e6c7e6488f7d8332c70d1ad0c497975a9 Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Thu, 12 Dec 2024 16:41:53 +0000 Subject: [PATCH 6/7] php.yml: Update to actions/cache@v4 --- .github/workflows/php.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 41cef68..70485e9 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -34,7 +34,7 @@ jobs: run: composer validate - name: Cache Composer cache - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ~/.composer/cache key: composer-cache-php${{ matrix.php }} From 043f5e0ab9c034ee2a91366ea55d404d57df0549 Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Thu, 8 Jan 2026 01:21:36 +0000 Subject: [PATCH 7/7] php.yml: Test on PHP 8.5 --- .github/workflows/php.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 70485e9..de76a8d 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -19,6 +19,7 @@ jobs: - '8.2' - '8.3' - '8.4' + - '8.5' steps: - uses: actions/checkout@v2