[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
No known key found for this signature in database
GPG key ID: 955F0567380E586A

View file

@ -49,12 +49,21 @@ class phpbb_Sniffs_Namespaces_UnusedUseSniff implements Sniff
$phpcsFile->addError($error, $stack_pointer, 'FullName'); $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); $types = explode('|', $found_name);
if (in_array($short_name, $types, true)) foreach ($types as $type)
{
// Nullable type syntax
$type = (strpos($type, '?') === 0) ? substr($type, 1) : $type;
if ($short_name === $type)
{ {
return true; return true;
} }
}
return false; return false;
} }