Skip to content

Commit b74c4ea

Browse files
committed
fix(VariableComment): Allow phpcs:ignore comments before member variables
1 parent c43cb34 commit b74c4ea

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

coder_sniffer/Drupal/Sniffs/Commenting/VariableCommentSniff.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use PHP_CodeSniffer\Files\File;
1313
use PHP_CodeSniffer\Sniffs\AbstractVariableSniff;
14+
use PHP_CodeSniffer\Util\Tokens;
1415

1516
/**
1617
* Parses and verifies class property doc comments.
@@ -38,7 +39,7 @@ class VariableCommentSniff extends AbstractVariableSniff
3839
public function processMemberVar(File $phpcsFile, $stackPtr)
3940
{
4041
$tokens = $phpcsFile->getTokens();
41-
$ignore = [
42+
$ignore = ([
4243
T_PUBLIC => T_PUBLIC,
4344
T_PRIVATE => T_PRIVATE,
4445
T_PROTECTED => T_PROTECTED,
@@ -57,7 +58,7 @@ public function processMemberVar(File $phpcsFile, $stackPtr)
5758
T_FALSE => T_FALSE,
5859
T_SELF => T_SELF,
5960
T_PARENT => T_PARENT,
60-
];
61+
] + Tokens::$phpcsCommentTokens);
6162

6263
for ($commentEnd = ($stackPtr - 1); $commentEnd >= 0; $commentEnd--) {
6364
if (isset($ignore[$tokens[$commentEnd]['code']]) === true) {

tests/Drupal/Commenting/VariableCommentUnitTest.inc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,10 @@ class Test {
9696
*/
9797
protected UserStorageInterface&MockObject $userStorageMock2;
9898

99+
/**
100+
* The search score.
101+
*/
102+
// phpcs:ignore Drupal.NamingConventions.ValidVariableName.LowerCamelName
103+
public string $search_score;
104+
99105
}

tests/Drupal/Commenting/VariableCommentUnitTest.inc.fixed

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,10 @@ class Test {
100100
*/
101101
protected UserStorageInterface&MockObject $userStorageMock2;
102102

103+
/**
104+
* The search score.
105+
*/
106+
// phpcs:ignore Drupal.NamingConventions.ValidVariableName.LowerCamelName
107+
public string $search_score;
108+
103109
}

0 commit comments

Comments
 (0)