Skip to content

Commit

Permalink
Merge branch 'php-8.0/squiz-variablecomment-support-attributes' of ht…
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Jul 28, 2021
2 parents 5f6d9ae + 72637ad commit 66d7385
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/Standards/Squiz/Sniffs/Commenting/VariableCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,32 @@ public function processMemberVar(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$ignore = [
T_PUBLIC,
T_PRIVATE,
T_PROTECTED,
T_VAR,
T_STATIC,
T_WHITESPACE,
T_STRING,
T_NS_SEPARATOR,
T_NULLABLE,
T_PUBLIC => T_PUBLIC,
T_PRIVATE => T_PRIVATE,
T_PROTECTED => T_PROTECTED,
T_VAR => T_VAR,
T_STATIC => T_STATIC,
T_WHITESPACE => T_WHITESPACE,
T_STRING => T_STRING,
T_NS_SEPARATOR => T_NS_SEPARATOR,
T_NULLABLE => T_NULLABLE,
];

$commentEnd = $phpcsFile->findPrevious($ignore, ($stackPtr - 1), null, true);
for ($commentEnd = ($stackPtr - 1); $commentEnd >= 0; $commentEnd--) {
if (isset($ignore[$tokens[$commentEnd]['code']]) === true) {
continue;
}

if ($tokens[$commentEnd]['code'] === T_ATTRIBUTE_END
&& isset($tokens[$commentEnd]['attribute_opener']) === true
) {
$commentEnd = $tokens[$commentEnd]['attribute_opener'];
continue;
}

break;
}

if ($commentEnd === false
|| ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG
&& $tokens[$commentEnd]['code'] !== T_COMMENT)
Expand Down
20 changes: 20 additions & 0 deletions src/Standards/Squiz/Tests/Commenting/VariableCommentUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,23 @@ class Foo

var int $noComment = 1;
}

class HasAttributes
{
/**
* Short description of the member variable.
*
* @var array
*/
#[ORM\Id]#[ORM\Column("integer")]
private $id;

/**
* Short description of the member variable.
*
* @var array
*/
#[ORM\GeneratedValue]
#[ORM\Column(ORM\Column::T_INTEGER)]
protected $height;
}
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,23 @@ class Foo

var int $noComment = 1;
}

class HasAttributes
{
/**
* Short description of the member variable.
*
* @var array
*/
#[ORM\Id]#[ORM\Column("integer")]
private $id;

/**
* Short description of the member variable.
*
* @var array
*/
#[ORM\GeneratedValue]
#[ORM\Column(ORM\Column::T_INTEGER)]
protected $height;
}

0 comments on commit 66d7385

Please sign in to comment.