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 #62

Bug: T379481
  • Loading branch information
codders committed Dec 6, 2024
1 parent 7c54a89 commit 8a558b8
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 21 deletions.
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"require-dev": {
"phpunit/phpunit": "~8.5",
"mediawiki/mediawiki-codesniffer": "^34",
"mediawiki/mediawiki-codesniffer": "45.0.0",
"ockcyp/covers-validator": "~1.0",
"phpstan/phpstan": "^0.12.68",
"phpmd/phpmd": "^2.9.1"
Expand All @@ -51,5 +51,10 @@
"@test",
"@cs"
]
},
"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 @@ -12,4 +12,5 @@
<rule ref="Generic.Metrics.CyclomaticComplexity" />
<rule ref="Generic.Metrics.NestingLevel" />
<rule ref="Squiz.Operators.ValidLogicalOperators" />
<rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki"/>
</ruleset>
2 changes: 1 addition & 1 deletion src/ValueFormatters/FormatterOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use RuntimeException;

/**
* @license GPL-2.0+
* @license GPL-2.0-or-later
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
final class FormatterOptions {
Expand Down
2 changes: 1 addition & 1 deletion src/ValueFormatters/FormattingException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use RuntimeException;

/**
* @license GPL-2.0+
* @license GPL-2.0-or-later
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
class FormattingException extends RuntimeException {
Expand Down
4 changes: 2 additions & 2 deletions src/ValueFormatters/ValueFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Interface for value formatters, typically (but not limited to) expecting a DataValue object and
* returning a string.
*
* @license GPL-2.0+
* @license GPL-2.0-or-later
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
interface ValueFormatter {
Expand All @@ -17,7 +17,7 @@ interface ValueFormatter {
* Identifier for the option that holds the code of the language in which the formatter should
* operate.
*/
const OPT_LANG = 'lang';
public const OPT_LANG = 'lang';

/**
* @param mixed $value
Expand Down
6 changes: 3 additions & 3 deletions src/ValueParsers/ParseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use RuntimeException;

/**
* @license GPL-2.0+
* @license GPL-2.0-or-later
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
class ParseException extends RuntimeException {
Expand All @@ -23,11 +23,11 @@ class ParseException extends RuntimeException {
private $rawValue;

/**
* @param string $message A plain english message describing the error
* @param string $message A plain english message describing the error
* @param string|null $rawValue The raw value that failed to be parsed.
* @param string|null $expectedFormat An identifier for the format the raw value did not match
*/
public function __construct( string $message, string $rawValue = null, string $expectedFormat = null ) {
public function __construct( string $message, ?string $rawValue = null, ?string $expectedFormat = null ) {
parent::__construct( $message );
$this->expectedFormat = $expectedFormat;
$this->rawValue = $rawValue;
Expand Down
2 changes: 1 addition & 1 deletion src/ValueParsers/ParserOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use RuntimeException;

/**
* @license GPL-2.0+
* @license GPL-2.0-or-later
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
final class ParserOptions {
Expand Down
2 changes: 1 addition & 1 deletion src/ValueParsers/ValueParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Interface for value parsers, typically (but not limited to) expecting a string and returning a
* DataValue object.
*
* @license GPL-2.0+
* @license GPL-2.0-or-later
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
interface ValueParser {
Expand Down
14 changes: 11 additions & 3 deletions src/ValueValidators/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,30 @@
namespace ValueValidators;

/**
* @license GPL-2.0+
* @license GPL-2.0-or-later
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
class Error {

public const SEVERITY_ERROR = 9;
public const SEVERITY_WARNING = 4;

/** @var string */
private $text;

/** @var int */
private $severity;

/** @var ?string */
private $property;

/** @var string */
private $code;

/** @var array */
private $params;

public static function newError( string $text = '', string $property = null, string $code = 'invalid', array $params = [] ): self {
public static function newError( string $text = '', ?string $property = null, string $code = 'invalid', array $params = [] ): self {
return new self( $text, self::SEVERITY_ERROR, $property, $code, $params );
}

Expand All @@ -37,7 +45,7 @@ public function getText(): string {
}

/**
* @return integer, element of the ValueValidatorError::SEVERITY_ enum
* @return int element of the ValueValidatorError::SEVERITY_ enum
*/
public function getSeverity(): int {
return $this->severity;
Expand Down
5 changes: 4 additions & 1 deletion src/ValueValidators/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
namespace ValueValidators;

/**
* @license GPL-2.0+
* @license GPL-2.0-or-later
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
final class Result {

/** @var bool */
private $isValid;

/** @var array */
private $errors;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/ValueValidators/ValueValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace ValueValidators;

/**
* @license GPL-2.0+
* @license GPL-2.0-or-later
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
interface ValueValidator {
Expand Down
2 changes: 1 addition & 1 deletion tests/ValueFormatters/FormatterOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @group ValueFormatters
* @group DataValueExtensions
*
* @license GPL-2.0+
* @license GPL-2.0-or-later
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
class FormatterOptionsTest extends TestCase {
Expand Down
2 changes: 1 addition & 1 deletion tests/ValueParsers/ParserOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @group ValueParsers
* @group DataValueExtensions
*
* @license GPL-2.0+
* @license GPL-2.0-or-later
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
class ParserOptionsTest extends TestCase {
Expand Down
4 changes: 2 additions & 2 deletions tests/ValueValidators/ErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @group ValueValidators
* @group DataValueExtensions
*
* @license GPL-2.0+
* @license GPL-2.0-or-later
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
class ErrorTest extends TestCase {
Expand Down Expand Up @@ -49,7 +49,7 @@ public function testNewError() {
*/
$this->assertInstanceOf( 'ValueValidators\Error', $error );

$this->assertTrue( is_string( $error->getProperty() ) || is_null( $error->getProperty() ) );
$this->assertTrue( is_string( $error->getProperty() ) || $error->getProperty() === null );

if ( count( $args ) > 0 ) {
$this->assertSame( $args[0], $error->getText() );
Expand Down
4 changes: 2 additions & 2 deletions tests/ValueValidators/ResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @group ValueValidators
* @group DataValueExtensions
*
* @license GPL-2.0+
* @license GPL-2.0-or-later
* @author Daniel Kinzler
*/
class ResultTest extends TestCase {
Expand All @@ -23,7 +23,7 @@ public function testNewSuccess() {
$result = Result::newSuccess();

$this->assertTrue( $result->isValid() );
$this->assertEmpty( $result->getErrors() );
$this->assertCount( 0, $result->getErrors() );
}

public function testNewError() {
Expand Down

0 comments on commit 8a558b8

Please sign in to comment.