Skip to content

Commit 5da71ee

Browse files
authored
Merge pull request #1120 from PHPCSStandards/php-8.4/feature/squiz-comment-sniffs-support-asym-visibility
Squiz/Commenting sniffs: update for properties with asymmetric visibility
2 parents 2d4e793 + 8d9a663 commit 5da71ee

10 files changed

+119
-16
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/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/Sniffs/Commenting/VariableCommentSniff.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use PHP_CodeSniffer\Files\File;
1313
use PHP_CodeSniffer\Sniffs\AbstractVariableSniff;
1414
use PHP_CodeSniffer\Util\Common;
15+
use PHP_CodeSniffer\Util\Tokens;
1516

1617
class VariableCommentSniff extends AbstractVariableSniff
1718
{
@@ -28,11 +29,9 @@ class VariableCommentSniff extends AbstractVariableSniff
2829
*/
2930
public function processMemberVar(File $phpcsFile, $stackPtr)
3031
{
31-
$tokens = $phpcsFile->getTokens();
32-
$ignore = [
33-
T_PUBLIC => T_PUBLIC,
34-
T_PRIVATE => T_PRIVATE,
35-
T_PROTECTED => T_PROTECTED,
32+
$tokens = $phpcsFile->getTokens();
33+
$ignore = Tokens::$scopeModifiers;
34+
$ignore += [
3635
T_VAR => T_VAR,
3736
T_STATIC => T_STATIC,
3837
T_READONLY => T_READONLY,

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+
}

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

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,3 +469,20 @@ class PHP84FinalProperties {
469469
*/
470470
final int $hasDocblock;
471471
}
472+
473+
class AsymVisibility {
474+
/**
475+
* @var integer
476+
*/
477+
public(set) int $hasDocblockA;
478+
479+
/**
480+
* @var integer
481+
*/
482+
public protected(set) int $hasDocblockB;
483+
484+
/**
485+
* @var integer
486+
*/
487+
private(set) protected int $hasDocblockC;
488+
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,3 +469,20 @@ class PHP84FinalProperties {
469469
*/
470470
final int $hasDocblock;
471471
}
472+
473+
class AsymVisibility {
474+
/**
475+
* @var integer
476+
*/
477+
public(set) int $hasDocblockA;
478+
479+
/**
480+
* @var integer
481+
*/
482+
public protected(set) int $hasDocblockB;
483+
484+
/**
485+
* @var integer
486+
*/
487+
private(set) protected int $hasDocblockC;
488+
}

0 commit comments

Comments
 (0)