Skip to content

Commit

Permalink
Merge pull request #209 from fcool/bugfix/union-types-variable-comment
Browse files Browse the repository at this point in the history
Squiz/VariableComment: allow union and intersection types to be detected
  • Loading branch information
jrfnl authored Jan 2, 2024
2 parents d8ec087 + ebb6b37 commit eb88812
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/Standards/Squiz/Sniffs/Commenting/VariableCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ public function processMemberVar(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$ignore = [
T_PUBLIC => T_PUBLIC,
T_PRIVATE => T_PRIVATE,
T_PROTECTED => T_PROTECTED,
T_VAR => T_VAR,
T_STATIC => T_STATIC,
T_READONLY => T_READONLY,
T_WHITESPACE => T_WHITESPACE,
T_STRING => T_STRING,
T_NS_SEPARATOR => T_NS_SEPARATOR,
T_NULLABLE => T_NULLABLE,
T_PUBLIC => T_PUBLIC,
T_PRIVATE => T_PRIVATE,
T_PROTECTED => T_PROTECTED,
T_VAR => T_VAR,
T_STATIC => T_STATIC,
T_READONLY => T_READONLY,
T_WHITESPACE => T_WHITESPACE,
T_STRING => T_STRING,
T_NS_SEPARATOR => T_NS_SEPARATOR,
T_NULLABLE => T_NULLABLE,
T_TYPE_UNION => T_TYPE_UNION,
T_TYPE_INTERSECTION => T_TYPE_INTERSECTION,
];

for ($commentEnd = ($stackPtr - 1); $commentEnd >= 0; $commentEnd--) {
Expand Down
16 changes: 16 additions & 0 deletions src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,19 @@ class ReadOnlyProps

private readonly string $variable;
}

class UnionTypes
{
/**
* @var array|boolean
*/
private array|bool $variableName = array();
}

class IntersectionTypes
{
/**
* @var \Iterator|\Countable
*/
private \Iterator&\Countable $variableName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,19 @@ class ReadOnlyProps

private readonly string $variable;
}

class UnionTypes
{
/**
* @var array|boolean
*/
private array|bool $variableName = array();
}

class IntersectionTypes
{
/**
* @var \Iterator|\Countable
*/
private \Iterator&\Countable $variableName;
}

0 comments on commit eb88812

Please sign in to comment.