From 1b08a745084e2bbb52a194848ce0ff0b86478c81 Mon Sep 17 00:00:00 2001 From: rxu Date: Tue, 15 Apr 2025 20:15:17 +0700 Subject: [PATCH] [ticket/17496] Sniffer to support question mark nullable type syntax PHPBB-17496 --- .../phpbb/Sniffs/Namespaces/UnusedUseSniff.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) 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;