Add static return type for ParserOutput::getExternalLinks

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
This commit is contained in:
Arthur Taylor 2024-10-08 09:51:23 +02:00
parent bca1a4932c
commit 9ae964fde7

View file

@ -195,7 +195,7 @@ class ParserOutput extends CacheTime implements ContentMetadataCollector {
/**
* @var array<string,int> External link URLs, in the key only.
*/
private $mExternalLinks = [];
private array $mExternalLinks = [];
/**
* @var array<string,array<string,int>> 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;
}