Add missing typehints

Change-Id: Ia25c5bea1834a3fdd26f32a9d5ed097789329824
This commit is contained in:
Ed Sanders 2021-12-01 14:53:20 +00:00
parent 6045b09ceb
commit 8e4f08182e
8 changed files with 30 additions and 25 deletions

View file

@ -300,7 +300,7 @@ class CommentModifier {
*
* @param DocumentFragment $fragment Fragment
*/
public static function unwrapFragment( DocumentFragment $fragment ) {
public static function unwrapFragment( DocumentFragment $fragment ): void {
$childNodeList = iterator_to_array( $fragment->childNodes );
// Wrap orphaned list items
@ -514,7 +514,7 @@ class CommentModifier {
* @param ThreadItem $comment Comment being replied to
* @param Element $container Container of comment DOM nodes
*/
public static function addReply( ThreadItem $comment, Element $container ) {
public static function addReply( ThreadItem $comment, Element $container ): void {
$newParsoidItem = null;
// Transfer comment DOM to Parsoid DOM
// Wrap every root node of the document in a new list item (dd/li).
@ -537,7 +537,7 @@ class CommentModifier {
* @param CommentItem $comment Comment being replied to
* @param string $wikitext
*/
public static function addWikitextReply( $comment, $wikitext ) {
public static function addWikitextReply( CommentItem $comment, string $wikitext ): void {
$doc = $comment->getRange()->endContainer->ownerDocument;
$container = $doc->createElement( 'div' );
@ -563,7 +563,7 @@ class CommentModifier {
* @param CommentItem $comment Comment being replied to
* @param string $html
*/
public static function addHtmlReply( $comment, $html ) {
public static function addHtmlReply( CommentItem $comment, string $html ): void {
$doc = $comment->getRange()->endContainer->ownerDocument;
$container = $doc->createElement( 'div' );

View file

@ -90,7 +90,7 @@ class CommentParser {
* @param Node $node
* @return bool
*/
private static function isCommentSeparator( Node $node ) {
private static function isCommentSeparator( Node $node ): bool {
return $node instanceof Element && (
// Empty paragraphs (`<p><br></p>`) between indented comments mess up indentation detection
strtolower( $node->nodeName ) === 'br' ||
@ -540,7 +540,7 @@ class CommentParser {
* @param Element $link
* @return string|null Username, or null
*/
private static function getUsernameFromLink( Element $link ) {
private static function getUsernameFromLink( Element $link ): ?string {
$username = null;
$title = CommentUtils::getTitleFromUrl( $link->getAttribute( 'href' ) ?? '' );
if ( !$title ) {
@ -666,7 +666,7 @@ class CommentParser {
* @param Node $node
* @return int Appropriate NodeFilter constant
*/
public static function acceptOnlyNodesAllowingComments( Node $node ) {
public static function acceptOnlyNodesAllowingComments( Node $node ): int {
// The table of contents has a heading that gets erroneously detected as a section
if ( $node instanceof Element && $node->getAttribute( 'id' ) === 'toc' ) {
return NodeFilter::FILTER_REJECT;
@ -847,7 +847,7 @@ class CommentParser {
* @param Text $node
* @return ImmutableRange
*/
private function adjustSigRange( array $sigNodes, array $match, Text $node ) {
private function adjustSigRange( array $sigNodes, array $match, Text $node ): ImmutableRange {
$firstSigNode = end( $sigNodes );
$lastSigNode = $sigNodes[0];
@ -1247,7 +1247,7 @@ class CommentParser {
* @param ThreadItem $threadItem
* @return CommentItem|null
*/
private function getThreadStartComment( ThreadItem $threadItem ) {
private function getThreadStartComment( ThreadItem $threadItem ): ?CommentItem {
$oldest = null;
if ( $threadItem instanceof CommentItem ) {
$oldest = $threadItem;

View file

@ -139,7 +139,7 @@ class HookUtils {
* @return string 'test' if in the test group, 'control' if in the control group, or '' if they've
* never been in the test
*/
private static function determineUserABTestBucket( $user, $feature = null ): string {
private static function determineUserABTestBucket( UserIdentity $user, ?string $feature = null ): string {
$services = MediaWikiServices::getInstance();
$optionsManager = $services->getUserOptionsManager();
$dtConfig = $services->getConfigFactory()->makeConfig( 'discussiontools' );

View file

@ -39,9 +39,9 @@ trait DiscussionToolsEventTrait {
/**
* Get a link to the individual comment, if available.
*
* @return string Full URL linking to the comment
* @return string|null Full URL linking to the comment, null if not available
*/
protected function getCommentLink() {
protected function getCommentLink(): ?string {
if ( !$this->userCan( RevisionRecord::DELETED_TEXT ) ) {
return null;
}
@ -91,7 +91,7 @@ trait DiscussionToolsEventTrait {
*
* @return string The snippet, as plain text (may be empty)
*/
protected function getContentSnippet() {
protected function getContentSnippet(): string {
if ( !$this->userCan( RevisionRecord::DELETED_TEXT ) ) {
return '';
}

View file

@ -72,7 +72,7 @@ class EventDispatcher {
* @param array &$events
* @param RevisionRecord $newRevRecord
*/
public static function generateEventsForRevision( array &$events, RevisionRecord $newRevRecord ) {
public static function generateEventsForRevision( array &$events, RevisionRecord $newRevRecord ): void {
$services = MediaWikiServices::getInstance();
$dtConfig = $services->getConfigFactory()->makeConfig( 'discussiontools' );
@ -156,7 +156,7 @@ class EventDispatcher {
RevisionRecord $newRevRecord,
PageIdentity $title,
UserIdentity $user
) {
): void {
$newComments = self::groupCommentsByThreadAndName( $newParser->getThreadItems() );
$oldComments = self::groupCommentsByThreadAndName( $oldParser->getThreadItems() );
$addedComments = [];
@ -277,7 +277,7 @@ class EventDispatcher {
*
* @param RevisionRecord $newRevRecord
*/
protected static function addCommentChangeTag( RevisionRecord $newRevRecord ) {
protected static function addCommentChangeTag( RevisionRecord $newRevRecord ): void {
// Unclear if DeferredUpdates::addCallableUpdate() is needed,
// but every extension does it that way.
DeferredUpdates::addCallableUpdate( static function () use ( $newRevRecord ) {
@ -293,7 +293,7 @@ class EventDispatcher {
* @param Title $title
* @param string $itemName
*/
protected static function addAutoSubscription( UserIdentity $user, Title $title, string $itemName ) {
protected static function addAutoSubscription( UserIdentity $user, Title $title, string $itemName ): void {
$dtConfig = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'discussiontools' );
if (
@ -346,7 +346,12 @@ class EventDispatcher {
* @param UserIdentity $identity
* @return bool Whether events were logged
*/
protected static function logAddedComments( $addedComments, $newRevRecord, $title, $identity ) {
protected static function logAddedComments(
array $addedComments,
RevisionRecord $newRevRecord,
PageIdentity $title,
UserIdentity $identity
): bool {
global $wgDTSchemaEditAttemptStepOversample, $wgWMESchemaEditAttemptStepOversample, $wgDBname;
$context = RequestContext::getMain();
$request = $context->getRequest();
@ -422,7 +427,7 @@ class EventDispatcher {
* @param string $sessionId
* @return bool Whether to sample the session
*/
protected static function inEventSample( $sessionId ) {
protected static function inEventSample( string $sessionId ): bool {
global $wgDTSchemaEditAttemptStepSamplingRate, $wgWMESchemaEditAttemptStepSamplingRate;
// Sample 6.25%
$samplingRate = 0.0625;

View file

@ -67,7 +67,7 @@ class SubscriptionItem {
*
* @return string|null
*/
public function getCreatedTimestamp() {
public function getCreatedTimestamp(): ?string {
return $this->createdTimestamp;
}
@ -76,7 +76,7 @@ class SubscriptionItem {
*
* @return string|null
*/
public function getNotificationTimestamp() {
public function getNotificationTimestamp(): ?string {
return $this->notifiedTimestamp;
}

View file

@ -238,7 +238,7 @@ abstract class ThreadItem implements JsonSerializable {
/**
* @param ThreadItem $parent
*/
public function setParent( ThreadItem $parent ) {
public function setParent( ThreadItem $parent ): void {
$this->parent = $parent;
}

View file

@ -32,7 +32,7 @@ class MockEventDispatcher extends EventDispatcher {
RevisionRecord $newRevRecord,
PageIdentity $title,
UserIdentity $user
) {
): void {
parent::generateEventsFromParsers(
$events,
$oldParser,
@ -48,7 +48,7 @@ class MockEventDispatcher extends EventDispatcher {
*
* @param RevisionRecord $newRevRecord
*/
public static function addCommentChangeTag( RevisionRecord $newRevRecord ) {
public static function addCommentChangeTag( RevisionRecord $newRevRecord ): void {
}
/**
@ -58,7 +58,7 @@ class MockEventDispatcher extends EventDispatcher {
* @param Title $title
* @param string $itemName
*/
protected static function addAutoSubscription( UserIdentity $user, Title $title, string $itemName ) {
protected static function addAutoSubscription( UserIdentity $user, Title $title, string $itemName ): void {
}
}