Skip to content

Commit da9e7f8

Browse files
committed
Update BlankLineBefore Return/If sniffs to be satisfied if preceded by doc block comment
1 parent e5174a6 commit da9e7f8

6 files changed

+41
-2
lines changed

Sniffs/Formatting/BlankLineBeforeReturnSniff.php

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
6767
while ($current >= 0 && $tokens[$current]['line'] >= $previousLine) {
6868
if ($tokens[$current]['line'] == $previousLine
6969
&& $tokens[$current]['type'] !== 'T_WHITESPACE'
70+
&& $tokens[$current]['type'] !== 'T_DOC_COMMENT'
7071
&& $tokens[$current]['type'] !== 'T_COMMENT'
7172
) {
7273
$prevLineTokens[] = $tokens[$current]['type'];

Sniffs/Instaclick/BlankLineBeforeIfSniff.php

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
6767
while ($current >= 0 && $tokens[$current]['line'] >= $previousLine) {
6868
if ($tokens[$current]['line'] == $previousLine
6969
&& $tokens[$current]['type'] !== 'T_WHITESPACE'
70+
&& $tokens[$current]['type'] !== 'T_DOC_COMMENT'
7071
&& $tokens[$current]['type'] !== 'T_COMMENT'
7172
) {
7273
$prevLineTokens[] = $tokens[$current]['type'];

Tests/Formatting/BlankLineBeforeReturnUnitTest.inc

+14
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@ function validFunctionReturnThree()
1717
return;
1818
}
1919

20+
function validFunctionReturnFour()
21+
{
22+
// comment
23+
return;
24+
}
25+
26+
function validFunctionReturnFive()
27+
{
28+
/**
29+
* multi-line
30+
*/
31+
return;
32+
}
33+
2034
function invalidFunctionReturnOne()
2135
{
2236
echo "";

Tests/Formatting/BlankLineBeforeReturnUnitTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Symfony2_Tests_Formatting_BlankLineBeforeReturnUnitTest extends AbstractSn
3838
public function getErrorList()
3939
{
4040
return array(
41-
23 => 1,
41+
37 => 1,
4242
);
4343
}
4444

Tests/Instaclick/BlankLineBeforeIfUnitTest.inc

+23
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,29 @@ function validFunctionIfThree()
2020
}
2121
}
2222

23+
function validFunctionIfFour()
24+
{
25+
/* comment */
26+
if (true) {
27+
}
28+
}
29+
30+
function validFunctionIfFive()
31+
{
32+
// single line comment
33+
if (true) {
34+
}
35+
}
36+
37+
function validFunctionIfSix()
38+
{
39+
/**
40+
* multi-line doc block
41+
*/
42+
if (true) {
43+
}
44+
}
45+
2346
function invalidFunctionIfOne()
2447
{
2548
echo "";

Tests/Instaclick/BlankLineBeforeIfUnitTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Symfony2_Tests_Instaclick_BlankLineBeforeIfUnitTest extends AbstractSniffU
3838
public function getErrorList()
3939
{
4040
return array(
41-
26 => 1,
41+
49 => 1,
4242
);
4343
}
4444

0 commit comments

Comments
 (0)