Skip to content
Browse files

Fixed bug #19394 : Notice in NonExecutableCodeSniff. The sniff had a …

…problem with conditional exit statements.
  • Loading branch information...
1 parent 65d70f7 commit 21bb0eab5083c54ab12bb61ae8a4fb5aa0e8e4fc @gsherwood gsherwood committed Apr 23, 2012
View
14 CodeSniffer/Standards/Squiz/Sniffs/PHP/NonExecutableCodeSniff.php
@@ -63,6 +63,13 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
+ // If this token is preceeded with an "or", it only relates to one line
+ // and should be ignore. For example: fopen() or die().
+ $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
+ if ($tokens[$prev]['code'] === T_LOGICAL_OR) {
+ return;
+ }
+
// Collect closure function parenthesises to use later for supressing some errors.
$closureReturnParenthesises = array();
$closureToken = $phpcsFile->findNext(T_CLOSURE, $stackPtr);
@@ -203,9 +210,12 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
return;
}
- // Skip whole functions and classes because they are not
+ // Skip whole functions and classes/interfaces because they are not
// technically executed code, but rather declarations that may be used.
- if ($tokens[$i]['code'] === T_FUNCTION || $tokens[$i]['code'] === T_CLASS) {
+ if ($tokens[$i]['code'] === T_FUNCTION
+ || $tokens[$i]['code'] === T_CLASS
+ || $tokens[$i]['code'] === T_INTERFACE
+ ) {
$i = $tokens[$i]['scope_closer'];
continue;
}
View
6 CodeSniffer/Standards/Squiz/Tests/PHP/NonExecutableCodeUnitTest.inc
@@ -128,6 +128,12 @@ switch ($var) {
}
}
+defined('FOO') or die('error');
+interface myInterface {
+ function myFunc();
+}
+echo 'hello';
+
exit();
// Errors are thrown from here down from the exit() above.
View
8 CodeSniffer/Standards/Squiz/Tests/PHP/NonExecutableCodeUnitTest.php
@@ -76,11 +76,11 @@ public function getWarningList()
95 => 1,
105 => 1,
118 => 1,
- 134 => 1,
- 135 => 1,
- 136 => 1,
- 137 => 2,
+ 140 => 1,
141 => 1,
+ 142 => 1,
+ 143 => 2,
+ 147 => 1,
);
}//end getWarningList()
View
5 CodeSniffer/Tokens.php
@@ -74,6 +74,11 @@
define('T_NS_SEPARATOR', 1051);
}
+// Some PHP 5.4 tokens, replicated for lower versions.
+if (defined('T_TRAIT') === false) {
+ define('T_TRAIT', 1052);
+}
+
/**
* The Tokens class contains weightings for tokens based on their
* probability of occurance in a file.
View
1 package.xml
@@ -46,6 +46,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Fixed bug #19354 : Not recognizing references passed to method
- Fixed bug #19361 : CSS tokenzier generates errors when PHP embedded in CSS file
- Fixed bug #19374 : HEREDOC/NOWDOC Indentation problems
+ - Fixed bug #19394 : Notice in NonExecutableCodeSniff
</notes>
<contents>
<dir name="/">

0 comments on commit 21bb0ea

Please sign in to comment.
Something went wrong with that request. Please try again.