Skip to content

Commit 0f95abc

Browse files
authored
feat(FunctionComment): Docblock is not required for __constuct() methods (#3400560)
1 parent ba6e623 commit 0f95abc

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ public function process(File $phpcsFile, $stackPtr)
9393
break;
9494
}
9595

96+
// Constructor methods are exempt from requiring a docblock.
97+
// @see https://www.drupal.org/project/coder/issues/3400560.
98+
$methodName = $phpcsFile->getDeclarationName($stackPtr);
99+
if ($methodName === '__construct'
100+
&& $tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG
101+
&& $tokens[$commentEnd]['code'] !== T_COMMENT
102+
) {
103+
return;
104+
}
105+
96106
$beforeCommentEnd = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($commentEnd - 1), null, true);
97107
if (($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG
98108
&& $tokens[$commentEnd]['code'] !== T_COMMENT)

tests/Drupal/Commenting/FunctionCommentUnitTest.inc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,4 +947,14 @@ class Test3 {
947947
return [];
948948
}
949949

950+
}
951+
952+
/**
953+
* Test that docblock is optional for __construct methods.
954+
*/
955+
class Test43 {
956+
957+
public function __construct() {
958+
}
959+
950960
}

tests/Drupal/Commenting/FunctionCommentUnitTest.inc.fixed

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,3 +974,13 @@ class Test3 {
974974
}
975975

976976
}
977+
978+
/**
979+
* Test that docblock is optional for __construct methods.
980+
*/
981+
class Test43 {
982+
983+
public function __construct() {
984+
}
985+
986+
}

0 commit comments

Comments
 (0)