Skip to content

Commit b7c84a0

Browse files
committed
PEAR.Functions.FunctionDeclaration now reports an error for blank lines found inside a function declaration (ref #1360)
1 parent 244d084 commit b7c84a0

File tree

5 files changed

+12
-2
lines changed

5 files changed

+12
-2
lines changed

CodeSniffer/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php

+6
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,12 @@ public function processMultiLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $st
349349
} else if ($tokens[$i]['line'] !== $tokens[($i + 1)]['line']) {
350350
// This is an empty line, so don't check the indent.
351351
$foundIndent = $expectedIndent;
352+
353+
$error = 'Blank lines are not allowed in a multi-line function declaration';
354+
$fix = $phpcsFile->addFixableError($error, $i, 'EmptyLine');
355+
if ($fix === true) {
356+
$phpcsFile->fixer->replaceToken($i, '');
357+
}
352358
} else {
353359
$foundIndent = strlen($tokens[$i]['content']);
354360
}

CodeSniffer/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.inc.fixed

-2
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,7 @@ function foo(
208208

209209
function foo(
210210
$param1,
211-
212211
$param2,
213-
214212
$param3,
215213
) : SomeClass {
216214
}

CodeSniffer/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public function getErrorList()
6767
171 => 1,
6868
173 => 1,
6969
201 => 1,
70+
206 => 1,
71+
208 => 1,
7072
);
7173

7274
}//end getErrorList()

CodeSniffer/Standards/Squiz/Tests/Functions/MultiLineFunctionDeclarationUnitTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ public function getErrorList($testFile='MultiLineFunctionDeclarationUnitTest.inc
6363
137 => 1,
6464
141 => 2,
6565
142 => 1,
66+
158 => 1,
67+
160 => 1,
6668
);
6769
} else {
6870
$errors = array(

package.xml

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
2727
<license uri="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt">BSD 3-Clause License</license>
2828
<notes>
2929
- The PHP-supplied T_COALESCE_EQUAL token has been replicated for PHP versions before 7.2
30+
- PEAR.Functions.FunctionDeclaration now reports an error for blank lines found inside a function declaration
3031
- PEAR.Functions.FunctionDeclaration no longer reports indent errors for blank lines in a function declaration
3132
- Squiz.Functions.MultiLineFunctionDeclaration no longer reports errors for blank lines in a function declaration
3233
-- It would previously report that only one argument is allowed per line
@@ -45,6 +46,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
4546
- Fixed bug #1349 : Squiz.Strings.DoubleQuoteUsage.NotRequired message is badly formatted when string contains a CR newline char
4647
-- Thanks to Algirdas Gurevicius for the patch
4748
- Fixed bug #1350 : Invalid Squiz.Formatting.OperatorBracket error when using namespaces
49+
- Fixed bug #1369 : Empty line in multi-line function declaration cause infinite loop
4850
</notes>
4951
<contents>
5052
<dir name="/">

0 commit comments

Comments
 (0)