From 11aef1cc02c453552e35aad4f0018fb2b896915b Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Sat, 2 Mar 2019 17:01:18 +0000 Subject: [PATCH] logging: Remove 'null' return from ManualLogEntry::getTags() The documentation already claimed it returned array, this is now actually true. Follows-up 037c06e886c63. There are two ways it could be null: * The setTags() method was never called, and the class member was implicitly null by default. * The setTags() method was called with $tags = null. This happens WikiPage::doUpdateRestrictions() among other places. That could probably be fixed, but is out of scope for this change. The getTags() method of this clss appears to have no outside callers in MediaWiki core, nor in any other project indexed by Codesearch. Change-Id: Ib89c79ef90870506187c3c3b61464c2aa788c594 --- includes/logging/LogEntry.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/includes/logging/LogEntry.php b/includes/logging/LogEntry.php index 937fa3702b..c35bd99143 100644 --- a/includes/logging/LogEntry.php +++ b/includes/logging/LogEntry.php @@ -462,8 +462,8 @@ class ManualLogEntry extends LogEntryBase { /** @var int A rev id associated to the log entry */ protected $revId = 0; - /** @var array Change tags add to the log entry */ - protected $tags = null; + /** @var string[] Change tags add to the log entry */ + protected $tags = []; /** @var int Deletion state of the log entry */ protected $deleted; @@ -579,11 +579,16 @@ class ManualLogEntry extends LogEntryBase { /** * Set change tags for the log entry. * + * Passing `null` means the same as empty array, + * for compatibility with WikiPage::doUpdateRestrictions(). + * * @since 1.27 - * @param string|string[] $tags + * @param string|string[]|null $tags */ public function setTags( $tags ) { - if ( is_string( $tags ) ) { + if ( $tags === null ) { + $tags = []; + } elseif ( is_string( $tags ) ) { $tags = [ $tags ]; } $this->tags = $tags; @@ -776,7 +781,7 @@ class ManualLogEntry extends LogEntryBase { if ( $to === 'rc' || $to === 'rcandudp' ) { // save RC, passing tags so they are applied there - $rc->addTags( $this->getTags() ?? [] ); + $rc->addTags( $this->getTags() ); $rc->save( $rc::SEND_NONE ); } @@ -836,7 +841,7 @@ class ManualLogEntry extends LogEntryBase { /** * @since 1.27 - * @return array + * @return string[] */ public function getTags() { return $this->tags; -- 2.20.1