Skip to content

Commit c14c326

Browse files
authored
Merge pull request #126 from magento-commerce/imported-karyna-tsymbal-atwix-magento-coding-standard-335
[Imported] Fix Comment block is missing Failure when Attribute is present after the docblock
2 parents 6f0c9ac + 29970d6 commit c14c326

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

Magento2/Sniffs/Annotation/MethodArgumentsSniff.php

+16
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,23 @@ private function isTokenBeforeClosingCommentTagValid(string $type): bool
7070
private function validateCommentBlockExists(File $phpcsFile, int $previousCommentClosePtr, int $stackPtr): bool
7171
{
7272
$tokens = $phpcsFile->getTokens();
73+
$attributeFlag = false;
7374
for ($tempPtr = $previousCommentClosePtr + 1; $tempPtr < $stackPtr; $tempPtr++) {
75+
$tokenCode = $tokens[$tempPtr]['code'];
76+
77+
// Ignore attributes e.g. #[\ReturnTypeWillChange]
78+
if ($tokenCode === T_ATTRIBUTE_END) {
79+
$attributeFlag = false;
80+
continue;
81+
}
82+
if ($attributeFlag) {
83+
continue;
84+
}
85+
if ($tokenCode === T_ATTRIBUTE) {
86+
$attributeFlag = true;
87+
continue;
88+
}
89+
7490
if (!$this->isTokenBeforeClosingCommentTagValid($tokens[$tempPtr]['type'])) {
7591
return false;
7692
}

Magento2/Tests/Annotation/MethodArgumentsUnitTest.inc

+18
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,21 @@ public function invalidDocBlockShouldNotCauseFatalErrorInSniff(int $number): int
3333
{
3434
return $number;
3535
}
36+
37+
/**
38+
* Short description.
39+
*
40+
* @param string $text
41+
* @return string
42+
*/
43+
#[\ReturnTypeWillChange]
44+
public function methodWithAttributeAndValidDocblock(string $text): string
45+
{
46+
return $text;
47+
}
48+
49+
#[\ReturnTypeWillChange]
50+
public function methodWithAttributeAndWithoutDocblock(string $text): string
51+
{
52+
return $text;
53+
}

Magento2/Tests/Annotation/MethodArgumentsUnitTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public function getErrorList()
1818
12 => 1,
1919
21 => 1,
2020
32 => 1,
21+
50 => 1
2122
];
2223
}
2324

0 commit comments

Comments
 (0)