From d2d2d914cec368140b72b3365c28d5ebad3a95c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Sun, 10 Mar 2024 23:40:27 +0100 Subject: [PATCH] Move some doc comments to real type hints Change-Id: I64e3f7123c803ae2576c8b05824698d78a691018 --- includes/CommentFormatter.php | 38 +++++++++++++---------------------- includes/TreeWalker.php | 8 ++------ tests/phpunit/TestUtils.php | 7 +------ 3 files changed, 17 insertions(+), 36 deletions(-) diff --git a/includes/CommentFormatter.php b/includes/CommentFormatter.php index 52367d492..2c0e121ef 100644 --- a/includes/CommentFormatter.php +++ b/includes/CommentFormatter.php @@ -169,21 +169,16 @@ class CommentFormatter { * A topic container is the information displayed when the "Show discusion activity" user * preference is selected. This displays information such as the latest comment time, number * of comments, and number of editors in the discussion. - * - * @param Element &$wrapperNode - * @param ?ContentCommentItem $latestReplyItem - * @param Document &$doc - * @param ContentHeadingItem &$headingItem - * @param ?Element &$bar - * @param array &$tocInfo */ protected static function addTopicContainer( - &$wrapperNode, $latestReplyItem, &$doc, &$headingItem, &$bar, &$tocInfo + Element &$wrapperNode, + ?ContentCommentItem $latestReplyItem, + Document &$doc, + ContentHeadingItem &$headingItem, + ?Element &$bar, + array &$tocInfo ) { - if ( !( - $wrapperNode instanceof Element && - DOMCompat::getClassList( $wrapperNode )->contains( 'mw-heading' ) - ) ) { + if ( !DOMCompat::getClassList( $wrapperNode )->contains( 'mw-heading' ) ) { DOMCompat::getClassList( $wrapperNode )->add( 'mw-heading' ); DOMCompat::getClassList( $wrapperNode )->add( 'mw-heading2' ); } @@ -224,16 +219,14 @@ class CommentFormatter { /** * Add a subscribe/unsubscribe link to the right of a heading element - * - * @param ContentHeadingItem $headingItem - * @param Document $doc - * @param Element $headingElement - * @param Element &$wrapperNode - * @param ?ContentCommentItem $latestReplyItem - * @param ?Element &$bar */ protected static function addSubscribeLink( - $headingItem, $doc, $headingElement, &$wrapperNode, $latestReplyItem, &$bar + ContentHeadingItem $headingItem, + Document $doc, + Element $headingElement, + Element &$wrapperNode, + ?ContentCommentItem $latestReplyItem, + ?Element &$bar ) { $headingJSONEscaped = htmlspecialchars( json_encode( static::getJsonForHeadingMarker( $headingItem ) ) @@ -459,11 +452,8 @@ class CommentFormatter { /** * Replace placeholders for all interactive tools with nothing. This is intended for cases where * interaction is unexpected, e.g. reply links while previewing an edit. - * - * @param string $text - * @return string */ - public static function removeInteractiveTools( string $text ) { + public static function removeInteractiveTools( string $text ): string { $text = strtr( $text, [ '' => '', ] ); diff --git a/includes/TreeWalker.php b/includes/TreeWalker.php index 2a372a391..1b8ec0610 100644 --- a/includes/TreeWalker.php +++ b/includes/TreeWalker.php @@ -19,21 +19,17 @@ class TreeWalker { public Node $root; public int $whatToShow; public Node $currentNode; - /** @var callable */ + /** @var callable|null */ public $filter; private bool $isActive = false; /** * See https://dom.spec.whatwg.org/#interface-treewalker - * - * @param Node $root - * @param int $whatToShow - * @param callable|null $filter */ public function __construct( Node $root, int $whatToShow = NodeFilter::SHOW_ALL, - callable $filter = null + ?callable $filter = null ) { $this->currentNode = $root; $this->filter = $filter; diff --git a/tests/phpunit/TestUtils.php b/tests/phpunit/TestUtils.php index a4f000039..7fae02f3e 100644 --- a/tests/phpunit/TestUtils.php +++ b/tests/phpunit/TestUtils.php @@ -125,12 +125,7 @@ trait TestUtils { file_put_contents( __DIR__ . '/../' . $relPath, $html ); } - /** - * @param array $config - * @param array $data - * @return array - */ - private static function prepareConfig( array $config, array $data ) { + private static function prepareConfig( array $config, array $data ): array { return [ 'LanguageCode' => $config['wgContentLanguage'], 'ArticlePath' => $config['wgArticlePath'],