From b67429478914c28c6e2bce0662b66866bd2d30a7 Mon Sep 17 00:00:00 2001 From: Thiemo Kreuz Date: Thu, 3 Feb 2022 09:41:28 +0100 Subject: [PATCH] Fix/narrow visibility of several methods One method is only public to be able to test it. Others look like they have been made "protected by default", which is not needed anywhere. Change-Id: Ib2231f0b2a879323aa53f8d40a175527c5b131d8 --- includes/TemplateDataBlob.php | 16 ++++++++-------- tests/phpunit/TemplateDataBlobTest.php | 10 +++++++--- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/includes/TemplateDataBlob.php b/includes/TemplateDataBlob.php index 04b7df01..11278809 100644 --- a/includes/TemplateDataBlob.php +++ b/includes/TemplateDataBlob.php @@ -110,7 +110,7 @@ class TemplateDataBlob { * @return null|string Text value from the InterfaceText object or null if no suitable * match was found */ - protected static function getInterfaceTextInLanguage( stdClass $text, string $langCode ): ?string { + private function getInterfaceTextInLanguage( stdClass $text, string $langCode ): ?string { if ( isset( $text->$langCode ) ) { return $text->$langCode; } @@ -164,33 +164,33 @@ class TemplateDataBlob { // Root.description if ( $data->description !== null ) { - $data->description = self::getInterfaceTextInLanguage( $data->description, $langCode ); + $data->description = $this->getInterfaceTextInLanguage( $data->description, $langCode ); } foreach ( $data->params as $param ) { // Param.label if ( $param->label !== null ) { - $param->label = self::getInterfaceTextInLanguage( $param->label, $langCode ); + $param->label = $this->getInterfaceTextInLanguage( $param->label, $langCode ); } // Param.description if ( $param->description !== null ) { - $param->description = self::getInterfaceTextInLanguage( $param->description, $langCode ); + $param->description = $this->getInterfaceTextInLanguage( $param->description, $langCode ); } // Param.default if ( $param->default !== null ) { - $param->default = self::getInterfaceTextInLanguage( $param->default, $langCode ); + $param->default = $this->getInterfaceTextInLanguage( $param->default, $langCode ); } // Param.example if ( $param->example !== null ) { - $param->example = self::getInterfaceTextInLanguage( $param->example, $langCode ); + $param->example = $this->getInterfaceTextInLanguage( $param->example, $langCode ); } } foreach ( $data->sets as $setObj ) { - $label = self::getInterfaceTextInLanguage( $setObj->label, $langCode ); + $label = $this->getInterfaceTextInLanguage( $setObj->label, $langCode ); if ( $label === null ) { // Contrary to other InterfaceTexts, set label is not optional. If we're here it // means the template data from the wiki doesn't contain either the user language, @@ -210,7 +210,7 @@ class TemplateDataBlob { /** * @return string JSON */ - public function getJSON(): string { + protected function getJSON(): string { if ( $this->json === null ) { // Cache for repeat calls $this->json = json_encode( $this->data ); diff --git a/tests/phpunit/TemplateDataBlobTest.php b/tests/phpunit/TemplateDataBlobTest.php index b4b698fd..1518cf4f 100644 --- a/tests/phpunit/TemplateDataBlobTest.php +++ b/tests/phpunit/TemplateDataBlobTest.php @@ -685,7 +685,7 @@ class TemplateDataBlobTest extends MediaWikiIntegrationTestCase { return $calls; } - protected function getStatusText( Status $status ): string { + private function getStatusText( Status $status ): string { $str = Parser::stripOuterParagraph( $status->getHtml() ); // Unescape char references for things like "[, "]" and "|" for // cleaner test assertions and output @@ -715,7 +715,7 @@ class TemplateDataBlobTest extends MediaWikiIntegrationTestCase { * @param mixed $actual * @param string|null $message */ - protected function assertStrictJsonEquals( $expected, $actual, $message = null ) { + private function assertStrictJsonEquals( $expected, $actual, $message = null ) { // Lazy recursive strict comparison: Serialise to JSON and compare that // Sort first to ensure key-order $expected = json_decode( $expected, /* assoc = */ true ); @@ -730,7 +730,7 @@ class TemplateDataBlobTest extends MediaWikiIntegrationTestCase { ); } - protected function assertTemplateData( array $case ) { + private function assertTemplateData( array $case ) { // Expand defaults if ( !isset( $case['status'] ) ) { $case['status'] = true; @@ -740,6 +740,8 @@ class TemplateDataBlobTest extends MediaWikiIntegrationTestCase { } $t = TemplateDataBlob::newFromJSON( $this->db, $case['input'] ); + /** @var TemplateDataBlob $t */ + $t = TestingAccessWrapper::newFromObject( $t ); $actual = $t->getJSON(); $status = $t->getStatus(); @@ -759,6 +761,8 @@ class TemplateDataBlobTest extends MediaWikiIntegrationTestCase { // Assert this case roundtrips properly by running through the output as input. $t = TemplateDataBlob::newFromJSON( $this->db, $case['output'] ); + /** @var TemplateDataBlob $t */ + $t = TestingAccessWrapper::newFromObject( $t ); $status = $t->getStatus(); if ( !$status->isGood() ) {