Skip to content

Commit 56a6c5d

Browse files
committed
Respect /** This action is documented in some-class.php */ comment.
1 parent 8550a71 commit 56a6c5d

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

WPForms/Sniffs/Comments/ParamTagHooksSniff.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ public function process( File $phpcsFile, $stackPtr ) {
7070
return;
7171
}
7272

73-
$tokens = $phpcsFile->getTokens();
7473
$commentEnd = $phpcsFile->findPrevious( T_DOC_COMMENT_CLOSE_TAG, $stackPtr );
7574
$commentStart = $phpcsFile->findPrevious( T_DOC_COMMENT_OPEN_TAG, $commentEnd );
7675

WPForms/Tests/TestFiles/Comments/ParamTagHooks.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ function () {
178178

179179
// The next case generated the endless loop in the \WPForms\Sniffs\Comments\ParamTagHooksSniff::countArguments.
180180

181-
/** This action is documented in some-class.php. */
181+
/** This action is documented in some-class.php */
182182
do_action( 'wpforms_display_submit_after', $this->displaysubmit_after_action );
183183

184184
// This case generated 'You should have 39 @param tags' (39 as an example).
@@ -195,3 +195,11 @@ function () {
195195
'http://site.org/cool-page',
196196
[]
197197
);
198+
199+
// These actions/filters should not produce an error.
200+
201+
/** This action is documented in includes/class-frontend.php */
202+
do_action( 'wpforms_display_submit_after', $this->form_data );
203+
204+
/** This filter is documented in wp-includes/post-template.php */
205+
$content = apply_filters( 'the_content', $content );

WPForms/Tests/Tests/Comments/ParamTagHooksTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function testProcess() {
2222
$phpcsFile = $this->process( new ParamTagHooksSniff() );
2323

2424
$this->fileHasErrors( $phpcsFile, 'InvalidAlign', [ 49, 50, 51, 52, 53 ] );
25-
$this->fileHasErrors( $phpcsFile, 'InvalidParamTagsQuantity', [ 75, 182 ] );
25+
$this->fileHasErrors( $phpcsFile, 'InvalidParamTagsQuantity', [ 75 ] );
2626
$this->fileHasErrors( $phpcsFile, 'MissParamInfo', [ 103, 104, 105, 106, 107, 108, 109 ] );
2727
$this->fileHasErrors( $phpcsFile, 'AddStopSymbol', [ 133, 134, 138 ] );
2828
$this->fileHasErrors( $phpcsFile, 'ExtraSpacesAfterParamTag', [ 160, 161, 162, 163, 164 ] );

WPForms/Traits/DuplicateHook.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,31 @@ trait DuplicateHook {
2323
*/
2424
protected function isDuplicateHook( $commentStart, $tokens ) {
2525

26+
$commentEnd = isset( $tokens[ $commentStart ]['comment_closer'] ) ? $tokens[ $commentStart ]['comment_closer'] : false;
27+
2628
$see = $this->findTag( '@see', $commentStart, $tokens );
2729

28-
if ( ! $see ) {
29-
return false;
30-
}
30+
$seeTagFound = $see && $commentEnd && ( $see['tag'] < $commentEnd );
3131

32-
if ( $tokens[ $see['tag'] + 2 ]['code'] !== T_DOC_COMMENT_STRING ) {
33-
return false;
32+
if ( $seeTagFound ) {
33+
$commentStringPtr = $see['tag'] + 2;
34+
} else {
35+
$commentStringPtr = $commentStart + 2;
36+
37+
if ( $tokens[ $commentStart ]['line'] !== $tokens[ $commentEnd ]['line'] ) {
38+
return false;
39+
}
3440
}
3541

36-
if ( 0 === strpos( $tokens[ $see['tag'] + 2 ]['content'], 'This filter is documented in ' ) ) {
37-
return true;
42+
$content = $tokens[ $commentStringPtr ]['content'];
43+
44+
if ( $tokens[ $commentStringPtr ]['code'] !== T_DOC_COMMENT_STRING ) {
45+
return false;
3846
}
3947

40-
return 0 === strpos( $tokens[ $see['tag'] + 2 ]['content'], 'This action is documented in ' );
48+
return (
49+
0 === strpos( $content, 'This action is documented in ' ) ||
50+
0 === strpos( $content, 'This filter is documented in ' )
51+
);
4152
}
4253
}

0 commit comments

Comments
 (0)