From 9ae964fde73802554d33f99a74b7c91711621510 Mon Sep 17 00:00:00 2001 From: Arthur Taylor Date: Tue, 8 Oct 2024 09:51:23 +0200 Subject: [PATCH] Add static return type for `ParserOutput::getExternalLinks` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PHPUnit tests that mock the ParserOutput object are unable to correctly infer that the mock should return an empty array rather than null for `getExternalLinks`. This is currently causing test failures in SpamBlacklist in CI. Add the return type definition to the function field definition so that PHPUnit has a better chance at doing the right thing. Note that `getExternalLinks` returns `$this->mExternalLinks` by reference; if there’s some existing code which reassigns a non-array value to that reference (and, consequently, to `$this->mExternalLinks`, such code will start to throw TypeErrors during the assignment. Bug: T376633 Change-Id: I246d5541200c9d0c405f30ea9de091ff9c0e759c --- includes/parser/ParserOutput.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/parser/ParserOutput.php b/includes/parser/ParserOutput.php index a95bf52640b..6690287d76c 100644 --- a/includes/parser/ParserOutput.php +++ b/includes/parser/ParserOutput.php @@ -195,7 +195,7 @@ class ParserOutput extends CacheTime implements ContentMetadataCollector { /** * @var array External link URLs, in the key only. */ - private $mExternalLinks = []; + private array $mExternalLinks = []; /** * @var array> 2-D map of prefix/DBK (in keys only) @@ -799,7 +799,7 @@ class ParserOutput extends CacheTime implements ContentMetadataCollector { return $this->mFileSearchOptions; } - public function &getExternalLinks() { + public function &getExternalLinks(): array { return $this->mExternalLinks; }