Skip to content

Commit 4032f7d

Browse files
🐛 Fix the way comment before return is handled
1 parent 9a1cdb2 commit 4032f7d

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

SymfonyCustom/Sniffs/Formatting/BlankLineBeforeReturnSniff.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ public function process(File $phpcsFile, $stackPtr)
3737
$tokens = $phpcsFile->getTokens();
3838
$current = $stackPtr;
3939
$previousLine = $tokens[$stackPtr]['line'] - 1;
40-
$prevLineTokens = array();
40+
$prevLineTokens = array();
4141

4242
while ($current >= 0 && $tokens[$current]['line'] >= $previousLine) {
4343
if ($tokens[$current]['line'] === $previousLine
4444
&& 'T_WHITESPACE' !== $tokens[$current]['type']
4545
&& 'T_COMMENT' !== $tokens[$current]['type']
46+
&& 'T_DOC_COMMENT_STRING' !== $tokens[$current]['type']
47+
&& 'T_DOC_COMMENT_OPEN_TAG' !== $tokens[$current]['type']
4648
&& 'T_DOC_COMMENT_CLOSE_TAG' !== $tokens[$current]['type']
4749
&& 'T_DOC_COMMENT_WHITESPACE' !== $tokens[$current]['type']
4850
) {
@@ -62,7 +64,7 @@ public function process(File $phpcsFile, $stackPtr)
6264
$fix = $phpcsFile->addFixableError(
6365
'Missing blank line before return statement',
6466
$stackPtr,
65-
'MissedBlankLineBeforeRetrun'
67+
'MissedBlankLineBeforeReturn'
6668
);
6769

6870
if (true === $fix) {

SymfonyCustom/Tests/Formatting/BlankLineBeforeReturnUnitTest.inc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ function validFunctionReturnFive()
3131
return;
3232
}
3333

34+
function validFunctionReturnSix()
35+
{
36+
/** comment */
37+
return;
38+
}
39+
3440
function invalidFunctionReturnOne()
3541
{
3642
echo "";

SymfonyCustom/Tests/Formatting/BlankLineBeforeReturnUnitTest.inc.fixed

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ function validFunctionReturnFive()
3131
return;
3232
}
3333

34+
function validFunctionReturnSix()
35+
{
36+
/** comment */
37+
return;
38+
}
39+
3440
function invalidFunctionReturnOne()
3541
{
3642
echo "";

SymfonyCustom/Tests/Formatting/BlankLineBeforeReturnUnitTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class BlankLineBeforeReturnUnitTest extends AbstractSniffUnitTest
2222
public function getErrorList()
2323
{
2424
return array(
25-
37 => 1,
25+
43 => 1,
2626
);
2727
}
2828

0 commit comments

Comments
 (0)