From: Tim Düsterhus Date: Sat, 5 Jan 2013 17:26:25 +0000 (+0100) Subject: Properly handle extending a class with the same name in Sniff X-Git-Tag: 2.0.0_Beta_1~585 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=1a66638aa969685cde86da1d9ec3c6e484630edb;p=GitHub%2FWoltLab%2FWCF.git Properly handle extending a class with the same name in Sniff Fixes #1082 --- diff --git a/CodeSniff/WCF/Sniffs/Methods/MethodDeclarationSniff.php b/CodeSniff/WCF/Sniffs/Methods/MethodDeclarationSniff.php index 82eff153c1..0117c4b37f 100644 --- a/CodeSniff/WCF/Sniffs/Methods/MethodDeclarationSniff.php +++ b/CodeSniff/WCF/Sniffs/Methods/MethodDeclarationSniff.php @@ -26,8 +26,7 @@ class WCF_Sniffs_Methods_MethodDeclarationSniff extends PHP_CodeSniffer_Standard * * @return void */ - protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope) - { + protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope) { $tokens = $phpcsFile->getTokens(); $methodName = $phpcsFile->getDeclarationName($stackPtr); diff --git a/CodeSniff/WCF/Sniffs/Namespaces/ClassMustBeImportedSniff.php b/CodeSniff/WCF/Sniffs/Namespaces/ClassMustBeImportedSniff.php index be5038a2c8..736035c900 100644 --- a/CodeSniff/WCF/Sniffs/Namespaces/ClassMustBeImportedSniff.php +++ b/CodeSniff/WCF/Sniffs/Namespaces/ClassMustBeImportedSniff.php @@ -54,6 +54,13 @@ class WCF_Sniffs_Namespaces_ClassMustBeImportedSniff implements PHP_CodeSniffer_ $class .= $tokens[$i]['content']; } + $extends = $phpcsFile->findPrevious(array(T_EXTENDS), $stackPtr - 1, null, false, null, true); + // are we trying to extend a class with the same name? + if ($extends !== false) { + $newClass = $phpcsFile->findPrevious(T_STRING, $extends); + if ($tokens[$newClass]['content'] == $tokens[$end - 1]['content']) return; + } + $error = 'Namespaced classes (%s) must be imported with use.'; $data = array( $class