diff --git a/.phan/stubs/eventlogging.php b/.phan/stubs/eventlogging.php index c011c58f..f4f46dff 100644 --- a/.phan/stubs/eventlogging.php +++ b/.phan/stubs/eventlogging.php @@ -3,11 +3,6 @@ namespace MediaWiki\Extension\EventLogging; class EventLogging { - - /** - * @param string $streamName - * @param array $event - */ public static function submit( string $streamName, array $event ): void { } } diff --git a/.phpcs.xml b/.phpcs.xml index 68595d3e..5b40bf4c 100644 --- a/.phpcs.xml +++ b/.phpcs.xml @@ -3,6 +3,22 @@ + + + + + + + + + + + 5 + + + 5 + + . diff --git a/includes/Api/ApiTemplateData.php b/includes/Api/ApiTemplateData.php index c224213a..12f520f3 100644 --- a/includes/Api/ApiTemplateData.php +++ b/includes/Api/ApiTemplateData.php @@ -1,10 +1,4 @@ mPageSet ??= new ApiPageSet( $this ); return $this->mPageSet; @@ -281,4 +272,5 @@ class ApiTemplateData extends ApiBase { public function getHelpUrls() { return 'https://www.mediawiki.org/wiki/Special:MyLanguage/Extension:TemplateData'; } + } diff --git a/includes/Hooks.php b/includes/Hooks.php index eb681fd1..d16ca180 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -1,7 +1,5 @@ isLoaded( 'EventLogging' ) ) { return; } @@ -213,7 +203,7 @@ class Hooks implements * * @return string HTML to insert in the page. */ - public static function render( $input, $args, Parser $parser, $frame ) { + public static function render( ?string $input, array $args, Parser $parser, PPFrame $frame ): string { $parserOutput = $parser->getOutput(); $ti = TemplateDataBlob::newFromJSON( wfGetDB( DB_REPLICA ), $input ?? '' ); @@ -268,7 +258,6 @@ class Hooks implements $localizer = new TemplateDataMessageLocalizer( $lang ); $formatter = new TemplateDataHtmlFormatter( $localizer, $lang->getCode() ); $formatter->replaceEditLink( $text ); - } } @@ -315,7 +304,7 @@ class Hooks implements } if ( !$title->exists() ) { - $tplData[$tplTitle] = (object)[ "missing" => true ]; + $tplData[$tplTitle] = (object)[ 'missing' => true ]; continue; } @@ -331,7 +320,7 @@ class Hooks implements $props = $pageProps->getProperties( $title, 'templatedata' ); if ( !isset( $props[$pageId] ) ) { // No templatedata - $tplData[$tplTitle] = (object)[ "notemplatedata" => true ]; + $tplData[$tplTitle] = (object)[ 'notemplatedata' => true ]; continue; } @@ -339,7 +328,7 @@ class Hooks implements $status = $tdb->getStatus(); if ( !$status->isOK() ) { // Invalid data. Parsoid has no use for the error. - $tplData[$tplTitle] = (object)[ "notemplatedata" => true ]; + $tplData[$tplTitle] = (object)[ 'notemplatedata' => true ]; continue; } diff --git a/includes/TemplateDataBlob.php b/includes/TemplateDataBlob.php index 4dac071a..7b6dfa4d 100644 --- a/includes/TemplateDataBlob.php +++ b/includes/TemplateDataBlob.php @@ -1,8 +1,4 @@ tags * on wiki pages. + * @license GPL-2.0-or-later */ class TemplateDataBlob { - /** - * @var string - */ - protected $json; - - /** - * @var Status - */ - protected $status; + protected string $json; + protected Status $status; /** * Parse and validate passed JSON and create a blob handling @@ -117,9 +107,6 @@ class TemplateDataBlob { return null; } - /** - * @return Status - */ public function getStatus(): Status { return $this->status; } diff --git a/includes/TemplateDataCompressedBlob.php b/includes/TemplateDataCompressedBlob.php index 13febd1d..a803320c 100644 --- a/includes/TemplateDataCompressedBlob.php +++ b/includes/TemplateDataCompressedBlob.php @@ -1,8 +1,4 @@ localizer = $localizer; $this->languageCode = $languageCode; @@ -57,7 +53,7 @@ class TemplateDataHtmlFormatter { } } - $sorting = count( (array)$data->params ) > 1 ? " sortable" : ""; + $sorting = count( (array)$data->params ) > 1 ? ' sortable' : ''; $html = '
' . Html::element( 'p', [ @@ -138,12 +134,12 @@ class TemplateDataHtmlFormatter { * * @param string &$text */ - public function replaceEditLink( string &$text ) { + public function replaceEditLink( string &$text ): void { $localizer = $this->localizer; $text = preg_replace_callback( // Based on EDITSECTION_REGEX in ParserOutput '##s', - static function ( $m ) use ( $localizer ) { + static function ( array $m ) use ( $localizer ): string { $editsectionPage = Title::newFromText( htmlspecialchars_decode( $m[1] ) ); if ( !is_object( $editsectionPage ) ) { diff --git a/includes/TemplateDataMessageLocalizer.php b/includes/TemplateDataMessageLocalizer.php index 2398b480..ce347ba8 100644 --- a/includes/TemplateDataMessageLocalizer.php +++ b/includes/TemplateDataMessageLocalizer.php @@ -6,16 +6,13 @@ use Language; use MessageLocalizer; /** + * @license GPL-2.0-or-later * @codeCoverageIgnore Trivial facade */ class TemplateDataMessageLocalizer implements MessageLocalizer { - /** @var Language */ - private $language; + private Language $language; - /** - * @param Language $language - */ public function __construct( Language $language ) { $this->language = $language; } diff --git a/includes/TemplateDataNormalizer.php b/includes/TemplateDataNormalizer.php index 1e22f139..00fb912c 100644 --- a/includes/TemplateDataNormalizer.php +++ b/includes/TemplateDataNormalizer.php @@ -4,6 +4,9 @@ namespace MediaWiki\Extension\TemplateData; use stdClass; +/** + * @license GPL-2.0-or-later + */ class TemplateDataNormalizer { public const DEPRECATED_PARAMETER_TYPES = [ @@ -13,12 +16,8 @@ class TemplateDataNormalizer { 'string/wiki-file-name' => 'wiki-file-name', ]; - /** @var string */ private string $contentLanguageCode; - /** - * @param string $contentLanguageCode - */ public function __construct( string $contentLanguageCode ) { $this->contentLanguageCode = $contentLanguageCode; } @@ -26,7 +25,7 @@ class TemplateDataNormalizer { /** * @param stdClass $data Expected to be valid according to the {@see TemplateDataValidator} */ - public function normalize( stdClass $data ) { + public function normalize( stdClass $data ): void { $data->description ??= null; $data->sets ??= []; $data->maps ??= (object)[]; @@ -55,10 +54,7 @@ class TemplateDataNormalizer { } } - /** - * @param stdClass $paramObj - */ - private function normalizeParameter( stdClass $paramObj ) { + private function normalizeParameter( stdClass $paramObj ): void { $paramObj->label ??= null; $paramObj->description ??= null; $paramObj->required ??= false; @@ -91,7 +87,7 @@ class TemplateDataNormalizer { /** * @param string|stdClass &$text */ - private function normaliseInterfaceText( &$text ) { + private function normaliseInterfaceText( &$text ): void { if ( is_string( $text ) ) { $text = (object)[ $this->contentLanguageCode => $text ]; } diff --git a/includes/TemplateDataStatus.php b/includes/TemplateDataStatus.php index bc9c9587..19d55a68 100644 --- a/includes/TemplateDataStatus.php +++ b/includes/TemplateDataStatus.php @@ -4,6 +4,9 @@ namespace MediaWiki\Extension\TemplateData; use Status; +/** + * @license GPL-2.0-or-later + */ class TemplateDataStatus { /** diff --git a/includes/TemplateDataValidator.php b/includes/TemplateDataValidator.php index 81be41f9..69b0cee4 100644 --- a/includes/TemplateDataValidator.php +++ b/includes/TemplateDataValidator.php @@ -5,6 +5,9 @@ namespace MediaWiki\Extension\TemplateData; use Status; use stdClass; +/** + * @license GPL-2.0-or-later + */ class TemplateDataValidator { public const PREDEFINED_FORMATS = [ @@ -53,7 +56,7 @@ class TemplateDataValidator { ]; /** @var string[] */ - private $validParameterTypes; + private array $validParameterTypes; /** * @param string[] $additionalParameterTypes @@ -282,7 +285,7 @@ class TemplateDataValidator { } elseif ( count( $paramOrder ) < count( (array)$params ) ) { $missing = array_diff( array_keys( (array)$params ), $paramOrder ); return Status::newFatal( 'templatedata-invalid-missing', - "paramOrder[ \"" . implode( '", "', $missing ) . '" ]' ); + 'paramOrder[ "' . implode( '", "', $missing ) . '" ]' ); } // Validate each of the values corresponds to a parameter and that there are no @@ -413,10 +416,6 @@ class TemplateDataValidator { return null; } - /** - * @param string|null $format - * @return bool - */ private function isValidCustomFormatString( ?string $format ): bool { return $format && preg_match( '/^\n?{{ *_+\n? *\|\n? *_+ *= *_+\n? *}}\n?$/', $format ); } diff --git a/maintenance/validateTemplateData.php b/maintenance/validateTemplateData.php index 1724866b..f77c897f 100644 --- a/maintenance/validateTemplateData.php +++ b/maintenance/validateTemplateData.php @@ -9,6 +9,9 @@ require_once "$IP/maintenance/Maintenance.php"; use MediaWiki\Extension\TemplateData\TemplateDataBlob; use MediaWiki\Title\Title; +/** + * @license GPL-2.0-or-later + */ class ValidateTemplateData extends Maintenance { public function __construct() { @@ -60,6 +63,7 @@ class ValidateTemplateData extends Maintenance { $this->output( "Rows checked: {$rowsChecked}\n" ); $this->output( "Bad rows: {$badRows}\n" ); } + } $maintClass = ValidateTemplateData::class; diff --git a/tests/phpunit/SerializationTest.php b/tests/phpunit/SerializationTest.php index 472e9b6b..ebdef632 100644 --- a/tests/phpunit/SerializationTest.php +++ b/tests/phpunit/SerializationTest.php @@ -3,8 +3,8 @@ use MediaWiki\Extension\TemplateData\TemplateDataStatus; /** - * @group TemplateData * @covers \MediaWiki\Extension\TemplateData\TemplateDataStatus + * @license GPL-2.0-or-later */ class SerializationTest extends MediaWikiIntegrationTestCase { diff --git a/tests/phpunit/TemplateDataBlobTest.php b/tests/phpunit/TemplateDataBlobTest.php index a44ca1d4..58a48d20 100644 --- a/tests/phpunit/TemplateDataBlobTest.php +++ b/tests/phpunit/TemplateDataBlobTest.php @@ -8,12 +8,12 @@ use MediaWiki\Title\Title; use Wikimedia\TestingAccessWrapper; /** - * @group TemplateData * @group Database * @covers \MediaWiki\Extension\TemplateData\TemplateDataBlob * @covers \MediaWiki\Extension\TemplateData\TemplateDataCompressedBlob * @covers \MediaWiki\Extension\TemplateData\TemplateDataNormalizer * @covers \MediaWiki\Extension\TemplateData\TemplateDataValidator + * @license GPL-2.0-or-later */ class TemplateDataBlobTest extends MediaWikiIntegrationTestCase { @@ -1537,9 +1537,11 @@ HTML public function testGetHtml( array $data, string $expected ) { $t = TemplateDataBlob::newFromJSON( $this->db, json_encode( $data ) ); $localizer = new class implements MessageLocalizer { + public function msg( $key, ...$params ) { return new RawMessage( "($key)" ); } + }; $title = Title::newFromText( 'Template:Test/doc' ); $formatter = new TemplateDataHtmlFormatter( $localizer ); @@ -1550,4 +1552,5 @@ HTML $this->assertSame( $linedExpected, $linedActual ); } + }