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/title/TitleFactory.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/title/TitleFactory.php')
-rw-r--r-- | includes/title/TitleFactory.php | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/includes/title/TitleFactory.php b/includes/title/TitleFactory.php index 59b48314efdf..790b5f54f4b0 100644 --- a/includes/title/TitleFactory.php +++ b/includes/title/TitleFactory.php @@ -67,6 +67,16 @@ class TitleFactory { } /** + * @see Title::newFromPageIdentity + * @since 1.41 + * @param PageIdentity $pageIdentity + * @return Title + */ + public function newFromPageIdentity( PageIdentity $pageIdentity ): Title { + return Title::newFromPageIdentity( $pageIdentity ); + } + + /** * @see Title::castFromPageIdentity * @since 1.36 * @param PageIdentity|null $pageIdentity @@ -77,6 +87,16 @@ class TitleFactory { } /** + * @see Title::newFromPageReference + * @since 1.41 + * @param PageReference $pageReference + * @return Title + */ + public function newFromPageReference( PageReference $pageReference ): Title { + return Title::newFromPageReference( $pageReference ); + } + + /** * @see Title::castFromPageReference * @since 1.37 * @param PageReference|null $pageReference |