Skip to content

Commit 9843e89

Browse files
committed
Squiz FunctionCommentThrownTagSniff no longer reports errors if it can't find a function comment.
1 parent cad109a commit 9843e89

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

Diff for: CodeSniffer/Standards/Squiz/Sniffs/Commenting/FunctionCommentThrowTagSniff.php

+21-3
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,27 @@ protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $sta
6666
return;
6767
}
6868

69-
// Parse the function comment.
70-
$tokens = $phpcsFile->getTokens();
71-
$commentEnd = $phpcsFile->findPrevious(T_DOC_COMMENT, ($currScope - 1));
69+
$tokens = $phpcsFile->getTokens();
70+
71+
$find = array(
72+
T_COMMENT,
73+
T_DOC_COMMENT,
74+
T_CLASS,
75+
T_FUNCTION,
76+
T_OPEN_TAG,
77+
);
78+
79+
$commentEnd = $phpcsFile->findPrevious($find, ($currScope - 1));
80+
81+
if ($commentEnd === false) {
82+
return;
83+
}
84+
85+
if ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT) {
86+
// Function doesn't have a comment. Let someone else warn about that.
87+
return;
88+
}
89+
7290
$commentStart = ($phpcsFile->findPrevious(T_DOC_COMMENT, ($commentEnd - 1), null, true) + 1);
7391
$comment = $phpcsFile->getTokensAsString($commentStart, ($commentEnd - $commentStart + 1));
7492

Diff for: CodeSniffer/Standards/Squiz/Tests/Commenting/FunctionCommentThrowTagUnitTest.inc

+12
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,16 @@ class NamespacedException {
217217
throw new \Foo\Bar\FooBarException();
218218
}
219219
}
220+
221+
class Foo {
222+
/**
223+
* Comment
224+
*/
225+
public function foo() {
226+
}//end foo()
227+
228+
public function bar() {
229+
throw new Exception();
230+
}
231+
}
220232
?>

0 commit comments

Comments
 (0)