Skip to content

Commit 14704dd

Browse files
committed
AC-1339: Detect comment for typed class properties
1 parent e59094a commit 14704dd

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,20 @@ public function processMemberVar(File $phpcsFile, $stackPtr)
5757
$tokens = $phpcsFile->getTokens();
5858

5959
$commentEnd = $phpcsFile->findPrevious($this->ignoreTokens, ($stackPtr - 1), null, true);
60+
61+
if ($commentEnd !== false && $tokens[$commentEnd]['code'] === T_STRING) {
62+
$commentEnd = $phpcsFile->findPrevious($this->ignoreTokens, ($commentEnd - 1), null, true);
63+
}
64+
6065
if ($commentEnd === false
6166
|| ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG
62-
&& $tokens[$commentEnd]['code'] !== T_COMMENT)
67+
&& $tokens[$commentEnd]['code'] !== T_COMMENT
68+
&& $tokens[$commentEnd]['code'] !== T_STRING)
6369
) {
6470
$phpcsFile->addWarning('Missing PHP DocBlock for class property.', $stackPtr, 'Missing');
6571
return;
6672
}
73+
6774
$commentStart = $tokens[$commentEnd]['comment_opener'];
6875
$foundVar = null;
6976
foreach ($tokens[$commentStart]['comment_tags'] as $tag) {

Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.inc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,10 @@ class correctlyFormattedClassMemberDocBlock
120120
* @var test
121121
*/
122122
protected $test;
123+
124+
/**
125+
* @var string
126+
*/
127+
protected string $test;
128+
123129
}

0 commit comments

Comments
 (0)