From 75ddf53b752ae932e148b095b98af9c749b43057 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Wed, 6 Jan 2016 17:40:34 +0100 Subject: [PATCH] Allow namespaced functions in PHPCS --- .../Namespaces/ClassMustBeImportedSniff.php | 16 +++++++++++++++- wcfsetup/install/files/lib/system/WCF.class.php | 2 -- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CodeSniff/WCF/Sniffs/Namespaces/ClassMustBeImportedSniff.php b/CodeSniff/WCF/Sniffs/Namespaces/ClassMustBeImportedSniff.php index 0e1ba74ca7..bf432696a5 100644 --- a/CodeSniff/WCF/Sniffs/Namespaces/ClassMustBeImportedSniff.php +++ b/CodeSniff/WCF/Sniffs/Namespaces/ClassMustBeImportedSniff.php @@ -60,6 +60,20 @@ class WCF_Sniffs_Namespaces_ClassMustBeImportedSniff implements PHP_CodeSniffer_ $newClass = $phpcsFile->findNext(T_STRING, $tClass); if ($tokens[$newClass]['content'] == $tokens[$end - 1]['content']) return; } + $tNew = $phpcsFile->findPrevious(array(T_NEW), $stackPtr - 1); + + // are we trying to create a new object? + if ($tNew === false) { + // no + $parenthesis = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $end); + $nonParenthesis = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $end, null, true); + + // are we accessing something that's static? + if ($parenthesis !== false && $parenthesis < $nonParenthesis) { + // no -> this looks like a function call of a namespaced function + return; + } + } $error = 'Namespaced classes (%s) must be imported with use.'; $data = array( @@ -70,4 +84,4 @@ class WCF_Sniffs_Namespaces_ClassMustBeImportedSniff implements PHP_CodeSniffer_ } } } -} \ No newline at end of file +} diff --git a/wcfsetup/install/files/lib/system/WCF.class.php b/wcfsetup/install/files/lib/system/WCF.class.php index 1c79755274..93f521cd2c 100644 --- a/wcfsetup/install/files/lib/system/WCF.class.php +++ b/wcfsetup/install/files/lib/system/WCF.class.php @@ -242,9 +242,7 @@ class WCF { @header('HTTP/1.1 503 Service Unavailable'); try { - // @codingStandardsIgnoreStart \wcf\functions\exception\printThrowable($e); - // @codingStandardsIgnoreEnd } catch (\Throwable $e2) { echo "
An Exception was thrown while handling an Exception:\n\n";
-- 
2.20.1