Skip to content
Merged
23 changes: 22 additions & 1 deletion coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,15 @@ public function process(File $phpcsFile, $stackPtr)
continue;
}

// If there is a phpstan-ignore inline comment disregard it and continue searching backwards
// to find the function comment.
if ($this->tokenIsPhpstanComment($tokens[$commentEnd]) === true) {
$functionCodeStart = $commentEnd;
continue;
}

break;
}
}//end for

// Constructor methods are exempt from requiring a docblock.
// @see https://www.drupal.org/project/coder/issues/3400560.
Expand Down Expand Up @@ -182,6 +189,20 @@ public function process(File $phpcsFile, $stackPtr)
}//end process()


/**
* Determine if a token is a '@phpstan-' control comment.
*
* @param array<mixed> $token The token to be checked.
*
* @return bool True if the token contains a @phpstan comment.
*/
public static function tokenIsPhpstanComment($token)
{
return ($token['code'] === T_COMMENT && strpos($token['content'], ' @phpstan-') !== false);

}//end tokenIsPhpstanComment()


/**
* Process the return comment of this function comment.
*
Expand Down
11 changes: 10 additions & 1 deletion tests/Drupal/good/good.php
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ public function test8() {}

}

t('Some long mulit-line
t('Some long mulit-line
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My editor automatically removed trailing spaces. Was this space needed? If so, this change should be reverted.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, we need this space for testing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's intersting, because all the tests passed without it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted.

text is weird, but allowed.');

// Anonymous functions should not throw indentation errors here.
Expand Down Expand Up @@ -2003,3 +2003,12 @@ public function &get($instance_id) {
}

}

/**
* Test for @phpstan-ignore-next-line.
*
* Coder issue https://www.drupal.org/project/coder/issues/3516489
*/
// @phpstan-ignore-next-line missingType.return
public function ignore_phpstan_comment() {
}