Skip to content

Commit b0fbd0e

Browse files
committed
Squiz/DocCommentAlignment: update for properties with asymmetric visibility
Prevent false negatives for the "incorrect space before star" error. Includes tests.
1 parent f1eccf3 commit b0fbd0e

File tree

4 files changed

+44
-6
lines changed

4 files changed

+44
-6
lines changed

src/Standards/Squiz/Sniffs/Commenting/DocCommentAlignmentSniff.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function process(File $phpcsFile, $stackPtr)
5252
{
5353
$tokens = $phpcsFile->getTokens();
5454

55-
// We are only interested in function/class/interface doc block comments.
55+
// We are only interested in function/class/interface/enum/property/const doc block comments.
5656
$ignore = Tokens::$emptyTokens;
5757
if ($phpcsFile->tokenizerType === 'JS') {
5858
$ignore[] = T_EQUAL;
@@ -61,15 +61,14 @@ public function process(File $phpcsFile, $stackPtr)
6161
}
6262

6363
$nextToken = $phpcsFile->findNext($ignore, ($stackPtr + 1), null, true);
64-
$ignore = [
64+
65+
$ignore = Tokens::$scopeModifiers;
66+
$ignore += [
6567
T_CLASS => true,
6668
T_INTERFACE => true,
6769
T_ENUM => true,
6870
T_ENUM_CASE => true,
6971
T_FUNCTION => true,
70-
T_PUBLIC => true,
71-
T_PRIVATE => true,
72-
T_PROTECTED => true,
7372
T_STATIC => true,
7473
T_ABSTRACT => true,
7574
T_FINAL => true,

src/Standards/Squiz/Tests/Commenting/DocCommentAlignmentUnitTest.inc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,20 @@ final class FinalClassWithFinalProp
114114
*/
115115
final $property = 10;
116116
}
117+
118+
class AsymVisibility {
119+
/**
120+
* Stars should be aligned.
121+
*/
122+
public(set) int $prop = 1;
123+
124+
/**
125+
* Stars should be aligned.
126+
*/
127+
protected(set) int $prop = 1;
128+
129+
/**
130+
* Stars should be aligned.
131+
*/
132+
private(set) int $prop = 1;
133+
}

src/Standards/Squiz/Tests/Commenting/DocCommentAlignmentUnitTest.inc.fixed

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,20 @@ final class FinalClassWithFinalProp
114114
*/
115115
final $property = 10;
116116
}
117+
118+
class AsymVisibility {
119+
/**
120+
* Stars should be aligned.
121+
*/
122+
public(set) int $prop = 1;
123+
124+
/**
125+
* Stars should be aligned.
126+
*/
127+
protected(set) int $prop = 1;
128+
129+
/**
130+
* Stars should be aligned.
131+
*/
132+
private(set) int $prop = 1;
133+
}

src/Standards/Squiz/Tests/Commenting/DocCommentAlignmentUnitTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ public function getErrorList($testFile='')
6363
$errors[112] = 1;
6464
$errors[113] = 1;
6565
$errors[114] = 1;
66-
}
66+
67+
$errors[120] = 1;
68+
$errors[121] = 1;
69+
$errors[125] = 1;
70+
$errors[126] = 1;
71+
}//end if
6772

6873
return $errors;
6974

0 commit comments

Comments
 (0)