diff --git a/build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php b/build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php index fd3b6f6ba5..53d94493c6 100644 --- a/build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php +++ b/build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php @@ -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;