From 4e48a19503228a20e5be2155578740e39f82ce62 Mon Sep 17 00:00:00 2001 From: alistair3149 Date: Mon, 4 Nov 2024 18:41:17 -0500 Subject: [PATCH] =?UTF-8?q?refactor(core):=20=E2=99=BB=EF=B8=8F=20fix=20va?= =?UTF-8?q?rious=20phpcs=20issues?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/Api/ApiWebappManifest.php | 11 +++--- .../CitizenComponentPageHeading.php | 10 ++++- .../Components/CitizenComponentPageTools.php | 9 ++--- .../Components/CitizenComponentSearchBox.php | 10 ++--- .../Components/CitizenComponentSiteStats.php | 10 +---- includes/SkinCitizen.php | 3 +- .../CitizenComponentMenuListItemTest.php | 38 ------------------- 7 files changed, 23 insertions(+), 68 deletions(-) delete mode 100644 tests/phpunit/Unit/Components/CitizenComponentMenuListItemTest.php diff --git a/includes/Api/ApiWebappManifest.php b/includes/Api/ApiWebappManifest.php index 19cdcd03..41325c2c 100644 --- a/includes/Api/ApiWebappManifest.php +++ b/includes/Api/ApiWebappManifest.php @@ -40,12 +40,6 @@ class ApiWebappManifest extends ApiBase { /* 1 week */ private const CACHE_MAX_AGE = 604800; - /** - * Constructor - */ - public function __construct() { - } - /** * Execute the requested Api actions. */ @@ -124,6 +118,11 @@ class ApiWebappManifest extends ApiBase { return $icons; } + /** + * Get src, sizes, and type for each icon for the manifest + * + * @return array|null + */ private function getIconData( $logoPath, $logoContent ) { $imageSize = getimagesizefromstring( $logoContent ); if ( $imageSize !== false ) { diff --git a/includes/Components/CitizenComponentPageHeading.php b/includes/Components/CitizenComponentPageHeading.php index af87d155..acdd43fd 100644 --- a/includes/Components/CitizenComponentPageHeading.php +++ b/includes/Components/CitizenComponentPageHeading.php @@ -38,9 +38,9 @@ class CitizenComponentPageHeading implements CitizenComponent { /** * @param MessageLocalizer $localizer + * @param OutputPage $out * @param Language|StubUserLang $pageLang * @param Title $title - * @param OutputPage $out * @param string $titleData * @param UserIdentity $user */ @@ -192,7 +192,13 @@ class CitizenComponentPageHeading implements CitizenComponent { return $localizer->msg( 'citizen-tagline-ns-talk' )->parse(); } - $isRootUserPage = $title->inNamespace( NS_USER ) || ( defined( 'NS_USER_WIKI' ) && $title->inNamespace( NS_USER_WIKI ) ) || ( defined( 'NS_USER_WIKI' ) && $title->inNamespace( NS_USER_PROFILE ) ) && !$title->isSubpage(); + $isRootUserPage = ( + $title->inNamespace( NS_USER ) || + ( defined( 'NS_USER_WIKI' ) && $title->inNamespace( NS_USER_WIKI ) ) || + ( defined( 'NS_USER_WIKI' ) && $title->inNamespace( NS_USER_PROFILE ) ) + ) && + !$title->isSubpage(); + if ( $isRootUserPage ) { // Build user tagline if it is a top-level user page return $this->buildUserTagline(); diff --git a/includes/Components/CitizenComponentPageTools.php b/includes/Components/CitizenComponentPageTools.php index bb17d5e9..18d2824e 100644 --- a/includes/Components/CitizenComponentPageTools.php +++ b/includes/Components/CitizenComponentPageTools.php @@ -43,8 +43,8 @@ class CitizenComponentPageTools implements CitizenComponent { /** * @param Config $config * @param MessageLocalizer $localizer - * @param UserIdentity $user * @param Title $title + * @param UserIdentity $user * @param int $numLanguages * @param array $sidebarData * @param array $languagesData @@ -137,10 +137,9 @@ class CitizenComponentPageTools implements CitizenComponent { * @inheritDoc */ public function getTemplateData(): array { - $hasLanguages = ( - $this->languagesData && $this->languagesData[ 'is-empty'] !== true || - $this->variantsData && $this->variantsData[ 'is-empty'] !== true - ); + $hasLanguages = + ( $this->languagesData && $this->languagesData[ 'is-empty' ] !== true ) || + ( $this->variantsData && $this->variantsData[ 'is-empty' ] !== true ); $articleTools = $this->getArticleToolsData(); return [ diff --git a/includes/Components/CitizenComponentSearchBox.php b/includes/Components/CitizenComponentSearchBox.php index 5d849913..ebcba5d4 100644 --- a/includes/Components/CitizenComponentSearchBox.php +++ b/includes/Components/CitizenComponentSearchBox.php @@ -19,21 +19,16 @@ class CitizenComponentSearchBox implements CitizenComponent { /** @var array */ private $searchBoxData; - /** @var Skin */ - private $skin; - /** * @param MessageLocalizer $localizer * @param array $searchBoxData */ public function __construct( MessageLocalizer $localizer, - array $searchBoxData, - Skin $skin + array $searchBoxData ) { $this->localizer = $localizer; $this->searchBoxData = $searchBoxData; - $this->skin = $skin; } /** @@ -74,13 +69,14 @@ class CitizenComponentSearchBox implements CitizenComponent { */ public function getTemplateData(): array { $searchBoxData = $this->searchBoxData; + $randompageUrl = SpecialPage::getTitleFor( 'Randompage' )->getLocalURL(); return $searchBoxData += [ 'array-keyboard-hint' => $this->getKeyboardHintData(), 'msg-citizen-search-footer' => $this->getFooterMessage(), 'msg-citizen-search-toggle-shortcut' => '[/]', // TODO: Replace with SkinComponentUtils on 1.43 - 'html-random-href' => SpecialPage::getTitleFor( 'Randompage' )->getLocalURL(), + 'html-random-href' => $randompageUrl, ]; } } diff --git a/includes/Components/CitizenComponentSiteStats.php b/includes/Components/CitizenComponentSiteStats.php index 7a037a44..126f30d1 100644 --- a/includes/Components/CitizenComponentSiteStats.php +++ b/includes/Components/CitizenComponentSiteStats.php @@ -34,13 +34,7 @@ class CitizenComponentSiteStats implements CitizenComponent { ]; /** - * @return Config - */ - private function getConfig(): Config { - return $this->config; - } - - /** + * @param Config $config * @param MessageLocalizer $localizer * @param Language|StubUserLang $pageLang */ @@ -75,7 +69,7 @@ class CitizenComponentSiteStats implements CitizenComponent { * @inheritDoc */ public function getTemplateData(): array { - $config = $this->getConfig(); + $config = $this->config; if ( !$config->get( 'CitizenEnableDrawerSiteStats' ) ) { return []; } diff --git a/includes/SkinCitizen.php b/includes/SkinCitizen.php index 89b5eaca..685cad73 100644 --- a/includes/SkinCitizen.php +++ b/includes/SkinCitizen.php @@ -143,8 +143,7 @@ class SkinCitizen extends SkinMustache { ), 'data-search-box' => new CitizenComponentSearchBox( $localizer, - $parentData['data-search-box'], - $this + $parentData['data-search-box'] ), 'data-site-stats' => new CitizenComponentSiteStats( $config, diff --git a/tests/phpunit/Unit/Components/CitizenComponentMenuListItemTest.php b/tests/phpunit/Unit/Components/CitizenComponentMenuListItemTest.php deleted file mode 100644 index b69cdb64..00000000 --- a/tests/phpunit/Unit/Components/CitizenComponentMenuListItemTest.php +++ /dev/null @@ -1,38 +0,0 @@ -link = $link; - $this->class = $class; - $this->id = $id; - } - - /** - * @inheritDoc - */ - public function getTemplateData(): array { - return $this->link->getTemplateData() + [ - 'item-class' => $this->class, - 'item-id' => $this->id, - ]; - } -}