1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-28 04:20:32 +02:00

[ticket/17496] Sniffer to support question mark nullable type syntax

PHPBB-17496
This commit is contained in:
rxu
2025-04-15 20:15:17 +07:00
parent a5113d7cd3
commit 1b08a74508

View File

@@ -49,11 +49,20 @@ class phpbb_Sniffs_Namespaces_UnusedUseSniff implements Sniff
$phpcsFile->addError($error, $stack_pointer, 'FullName');
}
// Check for possible union types like string|MyType|null
/*
* Check for possible union types (like string|MyType|null)
* and question mark nullable type syntax (like ?MyType)
*/
$types = explode('|', $found_name);
if (in_array($short_name, $types, true))
foreach ($types as $type)
{
return true;
// Nullable type syntax
$type = (strpos($type, '?') === 0) ? substr($type, 1) : $type;
if ($short_name === $type)
{
return true;
}
}
return false;