Allow namespaced functions in PHPCS
authorTim Düsterhus <duesterhus@woltlab.com>
Wed, 6 Jan 2016 16:40:34 +0000 (17:40 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Wed, 6 Jan 2016 16:53:00 +0000 (17:53 +0100)
CodeSniff/WCF/Sniffs/Namespaces/ClassMustBeImportedSniff.php
wcfsetup/install/files/lib/system/WCF.class.php

index 0e1ba74ca74aacc7a8eebb94274b6993e98661f9..bf432696a5c28db1a2192a11c051245b50ac641c 100644 (file)
@@ -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
+}
index 1c797552746105e4066623a134b45d18fe48d473..93f521cd2c4ed7bc113dc3256c8967bd7775320c 100644 (file)
@@ -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 "<pre>An Exception was thrown while handling an Exception:\n\n";