Permalink
Browse files

Generic DuplicateClassNameSniff no longer reports duplicate errors if…

… multiple PHP open tags exist in a file
  • Loading branch information...
gsherwood committed Mar 19, 2013
1 parent 8d58ddd commit 27d1956d4c20b0aedb40f4cdd4770e00a356d170
@@ -59,9 +59,22 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
- $namespace = '';
- $stackPtr = $phpcsFile->findNext(array(T_CLASS, T_INTERFACE, T_NAMESPACE), $stackPtr);
+ $namespace = '';
+ $findTokens = array(
+ T_CLASS,
+ T_INTERFACE,
+ T_NAMESPACE,
+ T_CLOSE_TAG,
+ );
+
+ $stackPtr = $phpcsFile->findNext($findTokens, ($stackPtr + 1));
while ($stackPtr !== false) {
+ if ($tokens[$stackPtr]['code'] === T_CLOSE_TAG) {
+ // We can stop here. The sniff will continue from the next open
+ // tag when PHPCS reaches that token, if there is one.
+ return;
+ }
+
// Keep track of what namespace we are in.
if ($tokens[$stackPtr]['code'] === T_NAMESPACE) {
$nsEnd = $phpcsFile->findNext(
@@ -101,7 +114,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
}
}
- $stackPtr = $phpcsFile->findNext(array(T_CLASS, T_INTERFACE, T_NAMESPACE), ($stackPtr + 1));
+ $stackPtr = $phpcsFile->findNext($findTokens, ($stackPtr + 1));
}//end while
}//end process()
@@ -6,3 +6,7 @@ class Test{
<?php
}
}
+
+class Test{
+
+}
@@ -76,6 +76,11 @@ public function getWarningList($testFile='')
7 => 1,
);
break;
+ case 'DuplicateClassNameUnitTest.6.inc':
+ return array(
+ 10 => 1,
+ );
+ break;
default:
return array();
break;
View
@@ -36,7 +36,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
-- This allows you to create wrapper scripts for PHPCS more easily
- PSR2 MethodDeclarationSniff no longer generates a notice for methods named "_"
-- Thanks to Bart S for the patch
- - Generic DuplicateClassNameSniff no longer reports an error if multiple PHP open tags exist in a file
+ - Generic DuplicateClassNameSniff no longer reports an invalid error if multiple PHP open tags exist in a file
+ - Generic DuplicateClassNameSniff no longer reports duplicate errors if multiple PHP open tags exist in a file
- Fixed bug #19819 : Freeze with syntax error in use statement
- Fixed bug #19820 : Wrong message level in Generic_Sniffs_CodeAnalysis_EmptyStatementSniff
- Fixed bug #19859 : CodeSniffer::setIgnorePatterns API changed

0 comments on commit 27d1956

Please sign in to comment.