Skip to content

Commit 446a484

Browse files
committed
Merge branch 'master' into 3.0
2 parents 20a659b + b7c84a0 commit 446a484

File tree

7 files changed

+39
-1
lines changed

7 files changed

+39
-1
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,15 @@ public function processMultiLineDeclaration($phpcsFile, $stackPtr, $tokens)
340340
// We changed lines, so this should be a whitespace indent token.
341341
if ($tokens[$i]['code'] !== T_WHITESPACE) {
342342
$foundIndent = 0;
343+
} else if ($tokens[$i]['line'] !== $tokens[($i + 1)]['line']) {
344+
// This is an empty line, so don't check the indent.
345+
$foundIndent = $expectedIndent;
346+
347+
$error = 'Blank lines are not allowed in a multi-line function declaration';
348+
$fix = $phpcsFile->addFixableError($error, $i, 'EmptyLine');
349+
if ($fix === true) {
350+
$phpcsFile->fixer->replaceToken($i, '');
351+
}
343352
} else {
344353
$foundIndent = strlen($tokens[$i]['content']);
345354
}

src/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.inc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,12 @@ function foo(
200200
): SomeClass // Comment here
201201
{
202202
}
203+
204+
function foo(
205+
$param1,
206+
207+
$param2,
208+
209+
$param3,
210+
) : SomeClass {
211+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,10 @@ function foo(
205205
): SomeClass { // Comment here
206206

207207
}
208+
209+
function foo(
210+
$param1,
211+
$param2,
212+
$param3,
213+
) : SomeClass {
214+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public function getErrorList($testFile='FunctionDeclarationUnitTest.inc')
5353
171 => 1,
5454
173 => 1,
5555
201 => 1,
56+
206 => 1,
57+
208 => 1,
5658
);
5759
} else {
5860
$errors = array(

src/Standards/Squiz/Sniffs/Functions/MultiLineFunctionDeclarationSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public function processBracket($phpcsFile, $openBracket, $tokens, $type='functio
187187
}
188188

189189
$next = $phpcsFile->findNext(T_WHITESPACE, ($i + 1), null, true);
190-
if ($tokens[$next]['line'] !== ($tokens[$i]['line'] + 1)) {
190+
if ($tokens[$next]['line'] === $tokens[$i]['line']) {
191191
$error = 'Multi-line '.$type.' declarations must define one parameter per line';
192192
$fix = $phpcsFile->addFixableError($error, $next, $errorPrefix.'OneParamPerLine');
193193
if ($fix === true) {

src/Standards/Squiz/Tests/Functions/MultiLineFunctionDeclarationUnitTest.inc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,12 @@ function foo(
152152
) {
153153
// body
154154
}
155+
156+
function foo(
157+
$param1,
158+
159+
$param2,
160+
161+
$param3,
162+
) : SomeClass {
163+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public function getErrorList($testFile='MultiLineFunctionDeclarationUnitTest.inc
4848
137 => 1,
4949
141 => 2,
5050
142 => 1,
51+
158 => 1,
52+
160 => 1,
5153
);
5254
} else {
5355
$errors = array(

0 commit comments

Comments
 (0)