Skip to content

Commit

Permalink
feat(FunctionComment): Docblock is not required for __constuct() meth…
Browse files Browse the repository at this point in the history
…ods (#3400560)
  • Loading branch information
jonathan1055 authored Jan 27, 2024
1 parent ba6e623 commit 0f95abc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ public function process(File $phpcsFile, $stackPtr)
break;
}

// Constructor methods are exempt from requiring a docblock.
// @see https://www.drupal.org/project/coder/issues/3400560.
$methodName = $phpcsFile->getDeclarationName($stackPtr);
if ($methodName === '__construct'
&& $tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG
&& $tokens[$commentEnd]['code'] !== T_COMMENT
) {
return;
}

$beforeCommentEnd = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($commentEnd - 1), null, true);
if (($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG
&& $tokens[$commentEnd]['code'] !== T_COMMENT)
Expand Down
10 changes: 10 additions & 0 deletions tests/Drupal/Commenting/FunctionCommentUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -947,4 +947,14 @@ class Test3 {
return [];
}

}

/**
* Test that docblock is optional for __construct methods.
*/
class Test43 {

public function __construct() {
}

}
10 changes: 10 additions & 0 deletions tests/Drupal/Commenting/FunctionCommentUnitTest.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -974,3 +974,13 @@ class Test3 {
}

}

/**
* Test that docblock is optional for __construct methods.
*/
class Test43 {

public function __construct() {
}

}

0 comments on commit 0f95abc

Please sign in to comment.