diff options
author | Bartosz Dziewoński <matma.rex@gmail.com> | 2023-04-22 15:57:00 +0200 |
---|---|---|
committer | Bartosz Dziewoński <matma.rex@gmail.com> | 2023-04-22 16:45:09 +0200 |
commit | 6ba47296d9bcf8397974e47bbc635377b9b3b304 (patch) | |
tree | 4e2fd750bf5dcaf9c4b35d0be073e77a31609208 /includes/api/ApiPageSet.php | |
parent | 774750b00dab24765ebf4bce26501eba288b1977 (diff) | |
download | mediawikicore-6ba47296d9bcf8397974e47bbc635377b9b3b304.tar.gz mediawikicore-6ba47296d9bcf8397974e47bbc635377b9b3b304.zip |
Fix Phan suppressions related to Title::castFrom*() and friends
There is no way to express that Title::castFromPageIdentity(),
Title::castFromPageReference() and Title::castFromLinkTarget()
can only return null when the parameter is null. We need to add
Phan suppressions or explicit types almost everywhere that these
methods are used with parameters that are known to not be null.
Instead, introduce new methods Title::newFromPageIdentity() and
Title::newFromPageReference() (Title::newFromLinkTarget() already
exists), without the null-coalescing behavior, and use them when
the parameter is not null. This lets static analysis tools, and
humans, easily understand where nulls can't appear.
Do the same with the corresponding TitleFactory methods.
Change the obvious uses of castFrom*() to newFrom*() (if there is
a Phan suppression, a type check, or a method call on the result).
Change-Id: Ida4da75953cf3bca372a40dc88022443109ca0cb
Diffstat (limited to 'includes/api/ApiPageSet.php')
-rw-r--r-- | includes/api/ApiPageSet.php | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/includes/api/ApiPageSet.php b/includes/api/ApiPageSet.php index 39611d1b62d4..019173e95111 100644 --- a/includes/api/ApiPageSet.php +++ b/includes/api/ApiPageSet.php @@ -1383,9 +1383,9 @@ class ApiPageSet extends ApiBase { continue; // There's nothing else we can do } } elseif ( $title instanceof LinkTarget ) { - $titleObj = $this->titleFactory->castFromLinkTarget( $title ); + $titleObj = $this->titleFactory->newFromLinkTarget( $title ); } else { - $titleObj = $this->titleFactory->castFromPageReference( $title ); + $titleObj = $this->titleFactory->newFromPageReference( $title ); } $titleObjects[$index] = $titleObj; @@ -1411,7 +1411,6 @@ class ApiPageSet extends ApiBase { // ILanguageConverter::findVariantLink will modify titleText and // titleObj into the canonical variant if possible $titleText = $title !== false ? $title : $titleObj->getPrefixedText(); - // @phan-suppress-next-line PhanTypeMismatchArgumentNullable castFrom does not return null here $this->languageConverter->findVariantLink( $titleText, $titleObj ); $titleWasConverted = $unconvertedTitle !== $titleObj->getPrefixedText(); } @@ -1447,7 +1446,6 @@ class ApiPageSet extends ApiBase { } } else { // Regular page - // @phan-suppress-next-line PhanTypeMismatchArgumentNullable castFrom does not return null here $linkBatch->addObj( $titleObj ); } } |