Skip to content

Squiz/Commenting sniffs: update for properties with asymmetric visibility #1120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/Standards/Squiz/Sniffs/Commenting/BlockCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function process(File $phpcsFile, $stackPtr)
return;
}

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

$ignore = [
$ignore = Tokens::$scopeModifiers;
$ignore += [
T_CLASS => true,
T_INTERFACE => true,
T_TRAIT => true,
T_ENUM => true,
T_FUNCTION => true,
T_PUBLIC => true,
T_PRIVATE => true,
T_FINAL => true,
T_PROTECTED => true,
T_STATIC => true,
T_ABSTRACT => true,
T_CONST => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();

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

$nextToken = $phpcsFile->findNext($ignore, ($stackPtr + 1), null, true);
$ignore = [

$ignore = Tokens::$scopeModifiers;
$ignore += [
T_CLASS => true,
T_INTERFACE => true,
T_ENUM => true,
T_ENUM_CASE => true,
T_FUNCTION => true,
T_PUBLIC => true,
T_PRIVATE => true,
T_PROTECTED => true,
T_STATIC => true,
T_ABSTRACT => true,
T_FINAL => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\AbstractVariableSniff;
use PHP_CodeSniffer\Util\Common;
use PHP_CodeSniffer\Util\Tokens;

class VariableCommentSniff extends AbstractVariableSniff
{
Expand All @@ -28,11 +29,9 @@ class VariableCommentSniff extends AbstractVariableSniff
*/
public function processMemberVar(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$ignore = [
T_PUBLIC => T_PUBLIC,
T_PRIVATE => T_PRIVATE,
T_PROTECTED => T_PROTECTED,
$tokens = $phpcsFile->getTokens();
$ignore = Tokens::$scopeModifiers;
$ignore += [
T_VAR => T_VAR,
T_STATIC => T_STATIC,
T_READONLY => T_READONLY,
Expand Down
17 changes: 17 additions & 0 deletions src/Standards/Squiz/Tests/Commenting/BlockCommentUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,20 @@ class FinalProperties {
*/
final int $prop = 1;
}

class AsymVisibility {
/**
* Comment should be ignored.
*/
public(set) int $prop = 1;

/**
* Comment should be ignored.
*/
protected(set) int $prop = 1;

/**
* Comment should be ignored.
*/
private(set) int $prop = 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,20 @@ class FinalProperties {
*/
final int $prop = 1;
}

class AsymVisibility {
/**
* Comment should be ignored.
*/
public(set) int $prop = 1;

/**
* Comment should be ignored.
*/
protected(set) int $prop = 1;

/**
* Comment should be ignored.
*/
private(set) int $prop = 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,20 @@ final class FinalClassWithFinalProp
*/
final $property = 10;
}

class AsymVisibility {
/**
* Stars should be aligned.
*/
public(set) int $prop = 1;

/**
* Stars should be aligned.
*/
protected(set) int $prop = 1;

/**
* Stars should be aligned.
*/
private(set) int $prop = 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,20 @@ final class FinalClassWithFinalProp
*/
final $property = 10;
}

class AsymVisibility {
/**
* Stars should be aligned.
*/
public(set) int $prop = 1;

/**
* Stars should be aligned.
*/
protected(set) int $prop = 1;

/**
* Stars should be aligned.
*/
private(set) int $prop = 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ public function getErrorList($testFile='')
$errors[112] = 1;
$errors[113] = 1;
$errors[114] = 1;
}

$errors[120] = 1;
$errors[121] = 1;
$errors[125] = 1;
$errors[126] = 1;
}//end if

return $errors;

Expand Down
17 changes: 17 additions & 0 deletions src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -469,3 +469,20 @@ class PHP84FinalProperties {
*/
final int $hasDocblock;
}

class AsymVisibility {
/**
* @var integer
*/
public(set) int $hasDocblockA;

/**
* @var integer
*/
public protected(set) int $hasDocblockB;

/**
* @var integer
*/
private(set) protected int $hasDocblockC;
}
Original file line number Diff line number Diff line change
Expand Up @@ -469,3 +469,20 @@ class PHP84FinalProperties {
*/
final int $hasDocblock;
}

class AsymVisibility {
/**
* @var integer
*/
public(set) int $hasDocblockA;

/**
* @var integer
*/
public protected(set) int $hasDocblockB;

/**
* @var integer
*/
private(set) protected int $hasDocblockC;
}