Skip to content

Commit 518f36a

Browse files
authored
Upgrade mediawiki-codesniffer to latest version (45.0.0) (#223)
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. Note that mediawiki-codesniffer 45.0.0 requires PHP version 7.4 or later - PHP 7.3 support will be dropped with this change. PHP 7.3 has been out of support since 6. Dec 2021. Resolves #222 Bug: T379481
1 parent cce979e commit 518f36a

22 files changed

+72
-69
lines changed

.github/workflows/php.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
php:
16-
- '7.3'
1716
- '7.4'
1817
- '8.0'
1918
- '8.1'

composer.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@
3838
"docs": "https://github.com/DataValues/Geo/#usage"
3939
},
4040
"require": {
41-
"php": ">=7.3",
41+
"php": ">=7.4",
4242
"data-values/data-values": "^3.0|^2.0|^1.0|~0.1",
4343
"data-values/interfaces": "^1.0.0|^0.2.0",
4444
"symfony/polyfill-php80": "^1.18.1"
4545
},
4646
"require-dev": {
4747
"phpunit/phpunit": "^9.4.1",
48-
"mediawiki/mediawiki-codesniffer": "^34 || ^35 || ^36 || ^38",
48+
"mediawiki/mediawiki-codesniffer": "^45",
4949
"ockcyp/covers-validator": "^1.3.3",
5050
"phpstan/phpstan": "^0.12.68 || ^1.0.0",
5151
"phpmd/phpmd": "^2.9.1",
@@ -83,5 +83,10 @@
8383
"@test",
8484
"@cs"
8585
]
86+
},
87+
"config": {
88+
"allow-plugins": {
89+
"dealerdirect/phpcodesniffer-composer-installer": true
90+
}
8691
}
8792
}

phpcs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212
<rule ref="Generic.Metrics.CyclomaticComplexity" />
1313
<rule ref="Generic.Metrics.NestingLevel" />
1414
<rule ref="Squiz.Operators.ValidLogicalOperators" />
15+
<rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki"/>
1516
</ruleset>

src/Formatters/GlobeCoordinateFormatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class GlobeCoordinateFormatter implements ValueFormatter {
3030
*/
3131
private $formatter;
3232

33-
public function __construct( FormatterOptions $options = null ) {
33+
public function __construct( ?FormatterOptions $options = null ) {
3434
$this->formatter = new LatLongFormatter( $options );
3535
}
3636

src/Formatters/LatLongFormatter.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ class LatLongFormatter implements ValueFormatter {
9393

9494
private const DEFAULT_PRECISION = 1 / 3600;
9595

96-
private $options;
96+
private FormatterOptions $options;
9797

98-
public function __construct( FormatterOptions $options = null ) {
98+
public function __construct( ?FormatterOptions $options = null ) {
9999
$this->options = $options ?? new FormatterOptions();
100100

101101
$this->defaultOption( self::OPT_NORTH_SYMBOL, 'N' );
@@ -211,7 +211,6 @@ private function formatLongitude( float $longitude, float $precision ): string {
211211

212212
private function makeDirectionalIfNeeded( string $coordinate, string $positiveSymbol,
213213
string $negativeSymbol ): string {
214-
215214
if ( $this->options->getOption( self::OPT_DIRECTIONAL ) ) {
216215
return $this->makeDirectional( $coordinate, $positiveSymbol, $negativeSymbol );
217216
}
@@ -221,7 +220,6 @@ private function makeDirectionalIfNeeded( string $coordinate, string $positiveSy
221220

222221
private function makeDirectional( string $coordinate, string $positiveSymbol,
223222
string $negativeSymbol ): string {
224-
225223
$isNegative = substr( $coordinate, 0, 1 ) === '-';
226224

227225
if ( $isNegative ) {

src/GlobeMath.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function normalizeGlobeCoordinate( GlobeCoordinateValue $value ): GlobeCo
5959
*
6060
* @return LatLongValue
6161
*/
62-
public function normalizeGlobeLatLong( LatLongValue $value, string $globe = null ): LatLongValue {
62+
public function normalizeGlobeLatLong( LatLongValue $value, ?string $globe = null ): LatLongValue {
6363
switch ( $this->normalizeGlobe( $globe ) ) {
6464
case GlobeCoordinateValue::GLOBE_EARTH:
6565
case self::GLOBE_MOON:

src/PackagePrivate/DmPrecisionDetector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class DmPrecisionDetector extends PrecisionDetector {
88

9-
private $dmsPrecisionDetector;
9+
private DmsPrecisionDetector $dmsPrecisionDetector;
1010

1111
public function __construct() {
1212
$this->dmsPrecisionDetector = new DmsPrecisionDetector();

src/PackagePrivate/LatLongPrecisionParser.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111

1212
class LatLongPrecisionParser {
1313

14-
private $options;
15-
private $parsers;
14+
private ?ParserOptions $options;
15+
private ?array $parsers = null;
1616

17-
public function __construct( ParserOptions $options = null ) {
17+
public function __construct( ?ParserOptions $options = null ) {
1818
$this->options = $options;
1919
}
2020

src/PackagePrivate/PreciseLatLong.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
class PreciseLatLong {
1010

11-
private $latLong;
12-
private $precision;
11+
private LatLongValue $latLong;
12+
private Precision $precision;
1313

1414
public function __construct( LatLongValue $latLong, Precision $precision ) {
1515
$this->latLong = $latLong;

src/PackagePrivate/Precision.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class Precision {
88

9-
private $precision;
9+
private float $precision;
1010

1111
public function __construct( float $precisionInDegrees ) {
1212
if ( $precisionInDegrees < -360 || $precisionInDegrees > 360 ) {

0 commit comments

Comments
 (0)