ci: 👷 lint code to MediaWiki standards

Check commit and GitHub actions for more details
This commit is contained in:
github-actions 2024-05-15 06:44:12 +00:00
parent d4d71dc34a
commit 1827a1b5c9

View file

@ -1,6 +1,6 @@
<?php
declare(strict_types=1);
declare( strict_types=1 );
namespace MediaWiki\Skins\Citizen\Components;
@ -13,8 +13,7 @@ use MessageLocalizer;
/**
* CitizenComponentUserInfo component
*/
class CitizenComponentUserInfo implements CitizenComponent
{
class CitizenComponentUserInfo implements CitizenComponent {
/** @var bool */
private $isRegistered;
@ -62,20 +61,19 @@ class CitizenComponentUserInfo implements CitizenComponent
*
* @return array|null
*/
private function getUserEditCount(): ?array
{
private function getUserEditCount(): ?array {
// Return user edits
$edits = MediaWikiServices::getInstance()->getUserEditTracker()->getUserEditCount($this->user);
$edits = MediaWikiServices::getInstance()->getUserEditTracker()->getUserEditCount( $this->user );
if (empty($edits)) {
if ( empty( $edits ) ) {
return null;
}
$label = $this->localizer->msg('usereditcount')->numParams($edits);
$label = str_replace($edits, '', $label);
$label = $this->localizer->msg( 'usereditcount' )->numParams( $edits );
$label = str_replace( $edits, '', $label );
return [
'count' => number_format($edits, 0),
'count' => number_format( $edits, 0 ),
'label' => $label
];
}
@ -85,35 +83,34 @@ class CitizenComponentUserInfo implements CitizenComponent
*
* @return array|null
*/
private function getUserGroups(): ?array
{
$groups = MediaWikiServices::getInstance()->getUserGroupManager()->getUserGroups($this->user);
private function getUserGroups(): ?array {
$groups = MediaWikiServices::getInstance()->getUserGroupManager()->getUserGroups( $this->user );
if (empty($groups)) {
if ( empty( $groups ) ) {
return null;
}
$listItems = [];
$msgKey = 'group-%s-member';
foreach ($groups as $group) {
$id = sprintf($msgKey, $group);
$text = $this->localizer->msg($id)->text();
foreach ( $groups as $group ) {
$id = sprintf( $msgKey, $group );
$text = $this->localizer->msg( $id )->text();
try {
$title = $this->title->newFromTextThrow($text, NS_PROJECT);
} catch (MalformedTitleException $e) {
$title = $this->title->newFromTextThrow( $text, NS_PROJECT );
} catch ( MalformedTitleException $e ) {
// ignore
}
if (!$text || !$title) {
if ( !$text || !$title ) {
continue;
}
$link = new CitizenComponentLink(
$title->getLinkURL(),
ucfirst($text)
ucfirst( $text )
);
$listItem = new CitizenComponentMenuListItem($link, 'citizen-userInfo-usergroup', $id);
$listItem = new CitizenComponentMenuListItem( $link, 'citizen-userInfo-usergroup', $id );
$listItems[] = $listItem->getTemplateData();
}
@ -128,14 +125,13 @@ class CitizenComponentUserInfo implements CitizenComponent
*
* @return array
*/
private function getUserPage(): array
{
private function getUserPage(): array {
$user = $this->user;
$userPageData = $this->userPageData;
$htmlItems = $userPageData['html-items'];
$realname = $user->getRealName();
if (!empty($realname)) {
if ( !empty( $realname ) ) {
$username = $user->getName();
$innerHtml = <<<HTML
<span id="pt-userpage-realname">$realname</span>
@ -149,12 +145,12 @@ class CitizenComponentUserInfo implements CitizenComponent
);
}
$menu = new CitizenComponentMenu([
$menu = new CitizenComponentMenu( [
'id' => 'citizen-user-menu-userpage',
'class' => null,
'label' => null,
'html-items' => $htmlItems
]);
] );
return $menu->getTemplateData();
}
@ -162,26 +158,25 @@ class CitizenComponentUserInfo implements CitizenComponent
/**
* @inheritDoc
*/
public function getTemplateData(): array
{
public function getTemplateData(): array {
$localizer = $this->localizer;
$data = [];
if ($this->isRegistered) {
if ( $this->isRegistered ) {
$data = [
'data-user-page' => $this->getUserPage(),
'data-user-edit' => $this->getUserEditCount()
];
if ($this->isTemp) {
$data['text'] = $localizer->msg('citizen-user-info-text-temp');
if ( $this->isTemp ) {
$data['text'] = $localizer->msg( 'citizen-user-info-text-temp' );
} else {
$data['data-user-groups'] = $this->getUserGroups();
}
} else {
$data = [
'title' => $localizer->msg('notloggedin'),
'text' => $localizer->msg('citizen-user-info-text-anon')
'title' => $localizer->msg( 'notloggedin' ),
'text' => $localizer->msg( 'citizen-user-info-text-anon' )
];
}