Skip to content

Commit

Permalink
Merge pull request #163 from wmde/php81-ci
Browse files Browse the repository at this point in the history
Add PHP 8.1 to CI, update mediawiki/mediawiki-codesniffer to ^39
  • Loading branch information
mariushoch authored Oct 21, 2022
2 parents c013e39 + 97fa95e commit 0096219
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 13 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ php:
- 7.3
- 7.4
- 8.0
- 8.1

install: travis_retry composer install

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"require-dev": {
"phpunit/phpunit": "~8.5",
"mediawiki/mediawiki-codesniffer": "34.0.0"
"mediawiki/mediawiki-codesniffer": "^39"
},
"autoload": {
"psr-0": {
Expand Down
2 changes: 1 addition & 1 deletion src/ValueParsers/MonthNameUnlocalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct( array $replacements ) {
$this->replacements = $replacements;

// Order search strings from longest to shortest
uksort( $this->replacements, function ( $a, $b ) {
uksort( $this->replacements, static function ( $a, $b ) {
return strlen( $b ) - strlen( $a );
} );
}
Expand Down
27 changes: 19 additions & 8 deletions src/ValueParsers/YearMonthTimeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,7 @@ public function __construct(
*/
protected function stringParse( $value ) {
list( $newValue, $sign ) = $this->splitBySignAndEra( $value );

// Matches year and month separated by a separator.
// \p{L} matches letters outside the ASCII range.
$regex = '/^(-?[\d\p{L}]+)\s*?[\/\-\s.,]\s*(-?[\d\p{L}]+)$/u';
if ( !preg_match( $regex, $newValue, $matches ) ) {
throw new ParseException( 'Failed to parse year and month', $value, self::FORMAT_NAME );
}
list( , $a, $b ) = $matches;
list( $a, $b ) = $this->splitByYearMonth( $value, $newValue );

// non-empty sign indicates the era (e.g. "BCE") was specified
// don't accept a negative number as the year
Expand Down Expand Up @@ -107,6 +100,24 @@ protected function stringParse( $value ) {
throw new ParseException( 'Failed to parse year and month', $value, self::FORMAT_NAME );
}

/**
* Returns two strings which can either be the month or year (depending on input order)
*
* @param string $originalValue The value as original given (for error reporting)
* @param string $newValue As produced by splitBySignAndEra
*
* @return array( string $a, string $b )
*/
private function splitByYearMonth( $originalValue, string $newValue ): array {
// Matches year and month separated by a separator.
// \p{L} matches letters outside the ASCII range.
$regex = '/^(-?[\d\p{L}]+)\s*?[\/\-\s.,]\s*(-?[\d\p{L}]+)$/u';
if ( !preg_match( $regex, $newValue, $matches ) ) {
throw new ParseException( 'Failed to parse year and month', $originalValue, self::FORMAT_NAME );
}
return array_splice( $matches, 1 );
}

/**
* @param string $value
*
Expand Down
2 changes: 1 addition & 1 deletion tests/DataValues/TimeValueCalculatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TimeValueCalculatorTest extends TestCase {
*/
private $calculator;

protected function setUp() : void {
protected function setUp(): void {
$this->calculator = new TimeValueCalculator();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ValueParsers/PhpDateTimeParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private function getEraParser() {
->method( 'parse' )
->with( $this->isType( 'string' ) )
->will( $this->returnCallback(
function ( $value ) {
static function ( $value ) {
$sign = '+';
// Tiny parser that supports a single negative sign only
if ( $value[0] === '-' ) {
Expand Down
2 changes: 1 addition & 1 deletion tests/ValueParsers/YearTimeParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private function getMockEraParser() {
->method( 'parse' )
->with( $this->isType( 'string' ) )
->will( $this->returnCallback(
function ( $value ) {
static function ( $value ) {
$sign = '+';
// Tiny parser that supports a single negative sign only
if ( $value[0] === '-' ) {
Expand Down

0 comments on commit 0096219

Please sign in to comment.