Skip to content

Commit f1eccf3

Browse files
committed
Squiz/BlockComment: update for properties with asymmetric visibility
Prevent false positives for the "block comments must start with ..." error. Includes tests.
1 parent 2d4e793 commit f1eccf3

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function process(File $phpcsFile, $stackPtr)
6666
return;
6767
}
6868

69-
// If this is a function/class/interface doc block comment, skip it.
69+
// If this is a function/class/interface/enum/property/const doc block comment, skip it.
7070
// We are only interested in inline doc block comments.
7171
if ($tokens[$stackPtr]['code'] === T_DOC_COMMENT_OPEN_TAG) {
7272
$nextToken = $stackPtr;
@@ -80,16 +80,14 @@ public function process(File $phpcsFile, $stackPtr)
8080
break;
8181
} while (true);
8282

83-
$ignore = [
83+
$ignore = Tokens::$scopeModifiers;
84+
$ignore += [
8485
T_CLASS => true,
8586
T_INTERFACE => true,
8687
T_TRAIT => true,
8788
T_ENUM => true,
8889
T_FUNCTION => true,
89-
T_PUBLIC => true,
90-
T_PRIVATE => true,
9190
T_FINAL => true,
92-
T_PROTECTED => true,
9391
T_STATIC => true,
9492
T_ABSTRACT => true,
9593
T_CONST => true,

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,3 +314,20 @@ class FinalProperties {
314314
*/
315315
final int $prop = 1;
316316
}
317+
318+
class AsymVisibility {
319+
/**
320+
* Comment should be ignored.
321+
*/
322+
public(set) int $prop = 1;
323+
324+
/**
325+
* Comment should be ignored.
326+
*/
327+
protected(set) int $prop = 1;
328+
329+
/**
330+
* Comment should be ignored.
331+
*/
332+
private(set) int $prop = 1;
333+
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,20 @@ class FinalProperties {
316316
*/
317317
final int $prop = 1;
318318
}
319+
320+
class AsymVisibility {
321+
/**
322+
* Comment should be ignored.
323+
*/
324+
public(set) int $prop = 1;
325+
326+
/**
327+
* Comment should be ignored.
328+
*/
329+
protected(set) int $prop = 1;
330+
331+
/**
332+
* Comment should be ignored.
333+
*/
334+
private(set) int $prop = 1;
335+
}

0 commit comments

Comments
 (0)