From 22b05a1e3ff708a059e238ef4f5dfa9ba6065f73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Mon, 12 Aug 2024 22:56:28 +0200 Subject: [PATCH] Replace gettype() with get_debug_type() in exception messages etc. get_debug_type() does the same thing but better (spelling type names in the same way as in type declarations, and including names of object classes and resource types). It was added in PHP 8, but the symfony/polyfill-php80 package provides it while we still support 7.4. Also remove uses of get_class() where the new method already provides the same information. For reference: https://www.php.net/manual/en/function.get-debug-type.php https://www.php.net/manual/en/function.gettype.php Change-Id: I54c2bf287b185e2526b0a8556166fd62182b2235 --- includes/CachedList.php | 2 +- includes/Controller/NotificationController.php | 2 +- includes/Iterator/FilteredSequentialIterator.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/CachedList.php b/includes/CachedList.php index 2fcafce44..6afc24895 100644 --- a/includes/CachedList.php +++ b/includes/CachedList.php @@ -57,7 +57,7 @@ class CachedList implements ContainmentList { if ( !is_array( $result ) ) { throw new UnexpectedValueException( sprintf( "Expected array but received '%s' from '%s::getValues'", - is_object( $result ) ? get_class( $result ) : gettype( $result ), + get_debug_type( $result ), get_class( $this->nestedList ) ) ); } diff --git a/includes/Controller/NotificationController.php b/includes/Controller/NotificationController.php index e7acf44fc..c44e24089 100644 --- a/includes/Controller/NotificationController.php +++ b/includes/Controller/NotificationController.php @@ -519,7 +519,7 @@ class NotificationController { $notify->addFilter( static function ( $user ) use ( &$seen, $fname ) { if ( !$user instanceof User ) { wfDebugLog( $fname, 'Expected all User instances, received: ' . - ( is_object( $user ) ? get_class( $user ) : gettype( $user ) ) + get_debug_type( $user ) ); return false; diff --git a/includes/Iterator/FilteredSequentialIterator.php b/includes/Iterator/FilteredSequentialIterator.php index 567fd2f07..71c4d5404 100644 --- a/includes/Iterator/FilteredSequentialIterator.php +++ b/includes/Iterator/FilteredSequentialIterator.php @@ -64,8 +64,8 @@ class FilteredSequentialIterator implements IteratorAggregate { } elseif ( $users instanceof IteratorAggregate ) { $it = $users->getIterator(); } else { - throw new InvalidArgumentException( 'Expected array, Iterator or IteratorAggregate but received:' . - ( is_object( $users ) ? get_class( $users ) : gettype( $users ) ) + throw new InvalidArgumentException( 'Expected array, Iterator or IteratorAggregate but received ' . + get_debug_type( $users ) ); }