Permalink
Browse files

Fixed bug #19463 :Anonymous functions incorrectly being flagged by No…

…nExecutableCodeSniff
  • Loading branch information...
1 parent 669d7ef commit 922eb0151285e2a97c80fe745710e4f3b6779305 @gsherwood gsherwood committed Jun 19, 2012
@@ -177,8 +177,6 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
}
}//end for
- $start = $phpcsFile->findNext(T_SEMICOLON, ($stackPtr + 1));
-
if ($nextOpener === null) {
$end = $closer;
} else {
@@ -191,10 +189,26 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
}
// Throw an error for all lines until the end of the file.
- $start = $phpcsFile->findNext(T_SEMICOLON, ($stackPtr + 1));
- $end = ($phpcsFile->numTokens - 1);
+ $end = ($phpcsFile->numTokens - 1);
}//end if
+ // Find the semicolon that ends this statement, skipping
+ // nested statements like FOR loops and closures.
+ for ($start = ($stackPtr + 1); $start < $phpcsFile->numTokens; $start++) {
+ if ($start === $end) {
+ break;
+ }
+
+ if ($tokens[$start]['code'] === T_OPEN_PARENTHESIS) {
+ $start = $tokens[$start]['parenthesis_closer'];
+ continue;
+ }
+
+ if ($tokens[$start]['code'] === T_SEMICOLON) {
+ break;
+ }
+ }
+
$lastLine = $tokens[$start]['line'];
for ($i = ($start + 1); $i < $end; $i++) {
if (in_array($tokens[$i]['code'], PHP_CodeSniffer_Tokens::$emptyTokens) === true
@@ -108,6 +108,11 @@ function myFunction()
}//end myFunction()
+public static function thisCausesAnError() {
+return new foo(function() {return $foo;}
+);
+}
+
function myFunction()
{
if ($something === TRUE) {
@@ -75,12 +75,12 @@ public function getWarningList()
83 => 1,
95 => 1,
105 => 1,
- 118 => 1,
- 140 => 1,
- 141 => 1,
- 142 => 1,
- 143 => 2,
+ 123 => 1,
+ 145 => 1,
+ 146 => 1,
147 => 1,
+ 148 => 2,
+ 152 => 1,
);
}//end getWarningList()
View
@@ -44,6 +44,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Fixed bug #19428 : PHPCS Report "hgblame" doesn't support windows paths
-- Thanks to Justin Rovang for the patch
- Fixed bug #19448 : Problem with detecting remote standards
+ - Fixed bug #19463 :Anonymous functions incorrectly being flagged by NonExecutableCodeSniff
- Fixed bug #19469 : PHP_CodeSniffer_File::getMemberProperties() sets wrong scope
- Fixed bug #19471 : phpcs on Windows, when using Zend standard, doesn't catch problems
-- Thanks to Ivan Habunek for the patch

0 comments on commit 922eb01

Please sign in to comment.