Skip to content

Commit 66d7385

Browse files
committed
Merge branch 'php-8.0/squiz-variablecomment-support-attributes' of https://github.com/jrfnl/PHP_CodeSniffer
2 parents 5f6d9ae + 72637ad commit 66d7385

File tree

3 files changed

+64
-10
lines changed

3 files changed

+64
-10
lines changed

src/Standards/Squiz/Sniffs/Commenting/VariableCommentSniff.php

+24-10
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,32 @@ public function processMemberVar(File $phpcsFile, $stackPtr)
3030
{
3131
$tokens = $phpcsFile->getTokens();
3232
$ignore = [
33-
T_PUBLIC,
34-
T_PRIVATE,
35-
T_PROTECTED,
36-
T_VAR,
37-
T_STATIC,
38-
T_WHITESPACE,
39-
T_STRING,
40-
T_NS_SEPARATOR,
41-
T_NULLABLE,
33+
T_PUBLIC => T_PUBLIC,
34+
T_PRIVATE => T_PRIVATE,
35+
T_PROTECTED => T_PROTECTED,
36+
T_VAR => T_VAR,
37+
T_STATIC => T_STATIC,
38+
T_WHITESPACE => T_WHITESPACE,
39+
T_STRING => T_STRING,
40+
T_NS_SEPARATOR => T_NS_SEPARATOR,
41+
T_NULLABLE => T_NULLABLE,
4242
];
4343

44-
$commentEnd = $phpcsFile->findPrevious($ignore, ($stackPtr - 1), null, true);
44+
for ($commentEnd = ($stackPtr - 1); $commentEnd >= 0; $commentEnd--) {
45+
if (isset($ignore[$tokens[$commentEnd]['code']]) === true) {
46+
continue;
47+
}
48+
49+
if ($tokens[$commentEnd]['code'] === T_ATTRIBUTE_END
50+
&& isset($tokens[$commentEnd]['attribute_opener']) === true
51+
) {
52+
$commentEnd = $tokens[$commentEnd]['attribute_opener'];
53+
continue;
54+
}
55+
56+
break;
57+
}
58+
4559
if ($commentEnd === false
4660
|| ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG
4761
&& $tokens[$commentEnd]['code'] !== T_COMMENT)

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

+20
Original file line numberDiff line numberDiff line change
@@ -363,3 +363,23 @@ class Foo
363363

364364
var int $noComment = 1;
365365
}
366+
367+
class HasAttributes
368+
{
369+
/**
370+
* Short description of the member variable.
371+
*
372+
* @var array
373+
*/
374+
#[ORM\Id]#[ORM\Column("integer")]
375+
private $id;
376+
377+
/**
378+
* Short description of the member variable.
379+
*
380+
* @var array
381+
*/
382+
#[ORM\GeneratedValue]
383+
#[ORM\Column(ORM\Column::T_INTEGER)]
384+
protected $height;
385+
}

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

+20
Original file line numberDiff line numberDiff line change
@@ -363,3 +363,23 @@ class Foo
363363

364364
var int $noComment = 1;
365365
}
366+
367+
class HasAttributes
368+
{
369+
/**
370+
* Short description of the member variable.
371+
*
372+
* @var array
373+
*/
374+
#[ORM\Id]#[ORM\Column("integer")]
375+
private $id;
376+
377+
/**
378+
* Short description of the member variable.
379+
*
380+
* @var array
381+
*/
382+
#[ORM\GeneratedValue]
383+
#[ORM\Column(ORM\Column::T_INTEGER)]
384+
protected $height;
385+
}

0 commit comments

Comments
 (0)