From fd8cb2a0e8370d0e8bb758ec97b9524fa2f53e1e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=C3=A1t=C3=A9=20Bartus?= <mate.bartus@gmail.com>
Date: Thu, 31 Dec 2020 15:22:50 +0100
Subject: [PATCH] [ticket/16671] Allow using objects from the global namespace

PHPBB3-16671
---
 .../phpbb/Sniffs/Namespaces/UnusedUseSniff.php     | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php b/build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php
index fedbef3a28..1b1c9935ee 100644
--- a/build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php
+++ b/build/code_sniffer/phpbb/Sniffs/Namespaces/UnusedUseSniff.php
@@ -29,18 +29,18 @@ class phpbb_Sniffs_Namespaces_UnusedUseSniff implements Sniff
 
 	protected function check(File $phpcsFile, $found_name, $full_name, $short_name, $stack_pointer)
 	{
-		$found_name = ltrim($found_name, '\\');
+		$found_name_normalized = ltrim($found_name, '\\');
 		$full_name = ltrim($full_name, '\\');
 
-		if ($found_name === $full_name)
+		$is_global = ($full_name === $short_name);
+		$unnecessarily_fully_qualified = ($is_global)
+			? ($found_name_normalized !== $found_name && $found_name_normalized === $short_name)
+			: ($found_name_normalized === $full_name);
+
+		if ($unnecessarily_fully_qualified)
 		{
 			$error = 'Either use statement or full name must be used.';
 			$phpcsFile->addError($error, $stack_pointer, 'FullName');
-
-			if (strpos($phpcsFile->getFilename(), 'cron/manager.php') !== false)
-			{
-				print("$found_name, $full_name, $short_name}\n");
-			}
 		}
 
 		if ($found_name === $short_name)