Skip to content

Commit 8d9a663

Browse files
committed
Squiz/VariableComment: update for properties with asymmetric visibility
Prevent false positives for the "no docblock found" error. Includes tests.
1 parent b0fbd0e commit 8d9a663

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

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/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)