Skip to content
Browse files

Fixed bug #19944 : docblock squiz sniff return void trips over return…

… in lambda function
  • Loading branch information...
1 parent 9378592 commit b63ca2ea9b448d26269ab3e8b554cd7a9276d06f @gsherwood gsherwood committed
View
18 CodeSniffer/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php
@@ -420,9 +420,21 @@ protected function processReturn($commentStart, $commentEnd)
// no return statement in the function.
if ($content === 'void') {
if (isset($tokens[$this->_functionToken]['scope_closer']) === true) {
- $endToken = $tokens[$this->_functionToken]['scope_closer'];
- $returnToken = $this->currentFile->findNext(T_RETURN, $this->_functionToken, $endToken);
- if ($returnToken !== false) {
+ $endToken = $tokens[$this->_functionToken]['scope_closer'];
+
+ $tokens = $this->currentFile->getTokens();
+ for ($returnToken = $this->_functionToken; $returnToken < $endToken; $returnToken++) {
+ if ($tokens[$returnToken]['code'] === T_CLOSURE) {
+ $returnToken = $tokens[$returnToken]['scope_closer'];
+ continue;
+ }
+
+ if ($tokens[$returnToken]['code'] === T_RETURN) {
+ break;
+ }
+ }
+
+ if ($returnToken !== $endToken) {
// If the function is not returning anything, just
// exiting, then there is no problem.
$semicolon = $this->currentFile->findNext(T_WHITESPACE, ($returnToken + 1), null, true);
View
13 CodeSniffer/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc
@@ -566,6 +566,19 @@ public function variableArgs($a1, $a2)
}//end variableArgs()
/**
+ * Contains closure.
+ *
+ * @return void
+ */
+public function containsClosure()
+{
+ function ($e) {
+ return new Event($e);
+ },
+
+}//end containsClosure()
+
+/**
* 这是一条测试评论.
*
* @return void
View
1 package.xml
@@ -44,6 +44,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
-- Thanks to Harald Franndorfer for the patch
- Fixed bug #19935 : notify-send reports do not vanish in gnome-shell
-- Thanks to Christian Weiske for the patch
+ - Fixed bug #19944 : docblock squiz sniff "return void" trips over return in lambda function
</notes>
<contents>
<dir name="/">

0 comments on commit b63ca2e

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