GetDebugTypeCanBeUsed
info on by default PHP ≥ 8.0Group: Language level migration · PhpStorm name: GetDebugTypeCanBeUsedInspection
The hand-rolled idiom "class name for objects, gettype() otherwise", written as a ternary over is_object(), is what PHP 8.0's get_debug_type() provides in one call. Suggest the built-in.
Example
Language level 8.1:
php
<?php
namespace Shop;
function label(object|string $payload, array $rows): array {
return [
is_object($rows[0]) ? get_class($rows[0]) : gettype($rows[0]),
'kind: ' . (\is_object($payload) ? \get_class($payload) : gettype($payload)),
is_object($payload) ? get_class($payload) : gettype($rows),
is_object($payload) ? gettype($payload) : get_class($payload),
is_object($payload) ? get_class($payload) : 'scalar',
is_object($payload) ?: gettype($payload),
(is_object($payload)) ? get_class($payload) : gettype($payload),
];
}Reported:
- line 6: Use 'get_debug_type($rows[0])' instead (scalar type names differ from gettype()).
- line 7: Use '\get_debug_type($payload)' instead (scalar type names differ from gettype()).
Configure
In custos.json:
json
{
"rules": {
"GetDebugTypeCanBeUsed": {
"enabled": false
}
}
}Suppress
Before the statement or declaration (or the first statement of the file), either of:
php
// @custos-ignore GetDebugTypeCanBeUsed
/**
* @noinspection GetDebugTypeCanBeUsedInspection
*/