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: I5e65a0759df7fa0c10bfa26ebc3cda436630f456
This commit is contained in:
Bartosz Dziewoński 2024-08-12 22:54:14 +02:00
parent 7d3642691b
commit 237d54d545
3 changed files with 4 additions and 4 deletions

View file

@ -98,7 +98,7 @@ class AFPData {
return new AFPData( self::DNULL );
default:
throw new InternalException(
'Data type ' . gettype( $var ) . ' is not supported by AbuseFilter'
'Data type ' . get_debug_type( $var ) . ' is not supported by AbuseFilter'
);
}
}

View file

@ -84,7 +84,7 @@ class VariablesManager {
} else {
// @codeCoverageIgnoreStart
throw new \UnexpectedValueException(
"Variable $varName has unexpected type " . gettype( $variable )
"Variable $varName has unexpected type " . get_debug_type( $variable )
);
// @codeCoverageIgnoreEnd
}

View file

@ -338,7 +338,7 @@ class UpdateVarDumps extends LoggedUpdateMaintenance {
}
if ( !is_array( $stored ) && !( $stored instanceof VariableHolder ) ) {
$this->fatalError(
'...found unexpected data type ( ' . gettype( $stored ) . ' ) in ' .
'...found unexpected data type ( ' . get_debug_type( $stored ) . ' ) in ' .
"afl_var_dump for afl_id {$row->afl_id}.\n"
);
}
@ -564,7 +564,7 @@ class UpdateVarDumps extends LoggedUpdateMaintenance {
} elseif ( is_array( $obj ) ) {
$varArray = $obj;
} else {
$type = is_object( $obj ) ? get_class( $obj ) : gettype( $obj );
$type = get_debug_type( $obj );
throw new UnexpectedValueException( "Unexpected type for stored blob: $type" );
}
$varArray = $this->updateVariables( $varArray );