From 6ba47296d9bcf8397974e47bbc635377b9b3b304 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Sat, 22 Apr 2023 15:57:00 +0200 Subject: 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 --- includes/title/TitleFactory.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'includes/title/TitleFactory.php') 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 @@ -66,6 +66,16 @@ class TitleFactory { return Title::castFromLinkTarget( $linkTarget ); } + /** + * @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 @@ -76,6 +86,16 @@ class TitleFactory { return Title::castFromPageIdentity( $pageIdentity ); } + /** + * @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 -- cgit v1.2.3