aboutsummaryrefslogtreecommitdiffstats
path: root/includes/libs
diff options
context:
space:
mode:
authorBartosz Dziewoński <dziewonski@fastmail.fm>2024-07-31 18:47:01 +0200
committerBartosz Dziewoński <dziewonski@fastmail.fm>2024-07-31 19:24:39 +0200
commitc045fa0291778f15c63b9bb73b1b840fe85ef62f (patch)
treec5c55c96deb99704d679a352442ea3c519c0cf8f /includes/libs
parent848b9fa281dc561a3af9668ec64e91725c4c0f67 (diff)
downloadmediawikicore-c045fa0291778f15c63b9bb73b1b840fe85ef62f.tar.gz
mediawikicore-c045fa0291778f15c63b9bb73b1b840fe85ef62f.zip
Replace gettype() with get_debug_type() in exception messages
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() and get_resource_type() 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 To keep this safe and simple to review, I'm only changing cases where the type is immediately used in an exception message. Change-Id: I325efcddcb58be63b1592b9c20ac0845393c15e2
Diffstat (limited to 'includes/libs')
-rw-r--r--includes/libs/MWCryptHash.php2
-rw-r--r--includes/libs/MapCacheLRU.php2
-rw-r--r--includes/libs/MemoizedCallable.php2
-rw-r--r--includes/libs/Message/ScalarParam.php2
-rw-r--r--includes/libs/ParamValidator/TypeDef/UploadDef.php2
-rw-r--r--includes/libs/rdbms/database/utils/QueryStatus.php2
-rw-r--r--includes/libs/rdbms/expression/LikeValue.php4
7 files changed, 8 insertions, 8 deletions
diff --git a/includes/libs/MWCryptHash.php b/includes/libs/MWCryptHash.php
index fea9dd2a9a20..215dee7ccf93 100644
--- a/includes/libs/MWCryptHash.php
+++ b/includes/libs/MWCryptHash.php
@@ -97,7 +97,7 @@ class MWCryptHash {
public static function hmac( $data, $key, $raw = true ) {
if ( !is_string( $key ) ) {
// hash_hmac tolerates non-string (would return null with warning)
- throw new InvalidArgumentException( 'Invalid key type: ' . gettype( $key ) );
+ throw new InvalidArgumentException( 'Invalid key type: ' . get_debug_type( $key ) );
}
return hash_hmac( self::hashAlgo(), $data, $key, $raw );
}
diff --git a/includes/libs/MapCacheLRU.php b/includes/libs/MapCacheLRU.php
index dae683d19f3a..2f184e7f7565 100644
--- a/includes/libs/MapCacheLRU.php
+++ b/includes/libs/MapCacheLRU.php
@@ -187,7 +187,7 @@ class MapCacheLRU implements ExpirationAwareness {
$this->ping( $key );
if ( !is_array( $this->cache[$key] ) ) {
- $type = gettype( $this->cache[$key] );
+ $type = get_debug_type( $this->cache[$key] );
throw new UnexpectedValueException( "Cannot add field to non-array value ('$key' is $type)" );
}
} else {
diff --git a/includes/libs/MemoizedCallable.php b/includes/libs/MemoizedCallable.php
index 3d797371a91c..b032b317fc6d 100644
--- a/includes/libs/MemoizedCallable.php
+++ b/includes/libs/MemoizedCallable.php
@@ -59,7 +59,7 @@ class MemoizedCallable {
if ( !is_callable( $callable, false, $this->callableName ) ) {
throw new InvalidArgumentException(
'Argument 1 passed to MemoizedCallable::__construct() must ' .
- 'be an instance of callable; ' . gettype( $callable ) . ' given'
+ 'be an instance of callable; ' . get_debug_type( $callable ) . ' given'
);
}
diff --git a/includes/libs/Message/ScalarParam.php b/includes/libs/Message/ScalarParam.php
index c63b49f6234a..59cbd83419b6 100644
--- a/includes/libs/Message/ScalarParam.php
+++ b/includes/libs/Message/ScalarParam.php
@@ -41,7 +41,7 @@ class ScalarParam extends MessageParam {
$value = (string)$value;
} elseif ( !is_string( $value ) && !is_numeric( $value ) &&
!$value instanceof MessageValue ) {
- $type = is_object( $value ) ? get_class( $value ) : gettype( $value );
+ $type = get_debug_type( $value );
throw new InvalidArgumentException(
"Scalar parameter must be a string, number, or MessageValue; got $type"
);
diff --git a/includes/libs/ParamValidator/TypeDef/UploadDef.php b/includes/libs/ParamValidator/TypeDef/UploadDef.php
index b651c9671e12..809893668a07 100644
--- a/includes/libs/ParamValidator/TypeDef/UploadDef.php
+++ b/includes/libs/ParamValidator/TypeDef/UploadDef.php
@@ -83,7 +83,7 @@ class UploadDef extends TypeDef {
if ( !$value instanceof UploadedFileInterface ) {
// Err?
- $type = is_object( $value ) ? get_class( $value ) : gettype( $value );
+ $type = get_debug_type( $value );
throw new InvalidArgumentException( "\$value must be UploadedFileInterface, got $type" );
}
diff --git a/includes/libs/rdbms/database/utils/QueryStatus.php b/includes/libs/rdbms/database/utils/QueryStatus.php
index f815e34cf15f..a854b45fdf1f 100644
--- a/includes/libs/rdbms/database/utils/QueryStatus.php
+++ b/includes/libs/rdbms/database/utils/QueryStatus.php
@@ -49,7 +49,7 @@ class QueryStatus {
if ( !( $res instanceof IResultWrapper ) && !is_bool( $res ) && $res !== null ) {
throw new DBUnexpectedError(
null,
- 'Got ' . gettype( $res ) . ' instead of IResultWrapper|bool'
+ 'Got ' . get_debug_type( $res ) . ' instead of IResultWrapper|bool'
);
}
diff --git a/includes/libs/rdbms/expression/LikeValue.php b/includes/libs/rdbms/expression/LikeValue.php
index f549fb0c113c..58b732927887 100644
--- a/includes/libs/rdbms/expression/LikeValue.php
+++ b/includes/libs/rdbms/expression/LikeValue.php
@@ -21,14 +21,14 @@ class LikeValue {
*/
public function __construct( $value, ...$values ) {
if ( !is_string( $value ) && !( $value instanceof LikeMatch ) ) {
- $type = is_object( $value ) ? get_class( $value ) : gettype( $value );
+ $type = get_debug_type( $value );
throw new InvalidArgumentException( "\$value must be string or LikeMatch, got $type" );
}
$this->values = [ $value ];
foreach ( $values as $value ) {
if ( !is_string( $value ) && !( $value instanceof LikeMatch ) ) {
- $type = is_object( $value ) ? get_class( $value ) : gettype( $value );
+ $type = get_debug_type( $value );
throw new InvalidArgumentException( "\$value must be string or LikeMatch, got $type" );
}
$this->values[] = $value;