From b7fdd3ebc86fbb4a484aaf2665e7f9bc700d3403 Mon Sep 17 00:00:00 2001 From: Greg Sherwood Date: Wed, 22 Feb 2017 07:38:46 +1100 Subject: [PATCH] PEAR.Functions.FunctionDeclaration no longer reports indent errors for blank lines in a function declaration (ref #1369) --- .../PEAR/Sniffs/Functions/FunctionDeclarationSniff.php | 3 +++ .../PEAR/Tests/Functions/FunctionDeclarationUnitTest.inc | 9 +++++++++ .../Functions/FunctionDeclarationUnitTest.inc.fixed | 9 +++++++++ package.xml | 1 + 4 files changed, 22 insertions(+) diff --git a/CodeSniffer/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php b/CodeSniffer/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php index c681257d9e..8a39744184 100644 --- a/CodeSniffer/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php +++ b/CodeSniffer/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php @@ -346,6 +346,9 @@ public function processMultiLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $st // We changed lines, so this should be a whitespace indent token. if ($tokens[$i]['code'] !== T_WHITESPACE) { $foundIndent = 0; + } else if ($tokens[$i]['line'] !== $tokens[($i + 1)]['line']) { + // This is an empty line, so don't check the indent. + $foundIndent = $expectedIndent; } else { $foundIndent = strlen($tokens[$i]['content']); } diff --git a/CodeSniffer/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.inc b/CodeSniffer/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.inc index cf2187c70c..363d967efc 100644 --- a/CodeSniffer/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.inc +++ b/CodeSniffer/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.inc @@ -200,3 +200,12 @@ function foo( ): SomeClass // Comment here { } + +function foo( + $param1, + + $param2, + + $param3, +) : SomeClass { +} diff --git a/CodeSniffer/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.inc.fixed b/CodeSniffer/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.inc.fixed index 80e378a364..870b3252c7 100644 --- a/CodeSniffer/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.inc.fixed +++ b/CodeSniffer/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.inc.fixed @@ -205,3 +205,12 @@ function foo( ): SomeClass { // Comment here } + +function foo( + $param1, + + $param2, + + $param3, +) : SomeClass { +} diff --git a/package.xml b/package.xml index ffa3666961..e4d2f30a7d 100644 --- a/package.xml +++ b/package.xml @@ -27,6 +27,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> BSD 3-Clause License - The PHP-supplied T_COALESCE_EQUAL token has been replicated for PHP versions before 7.2 + - PEAR.Functions.FunctionDeclaration no longer reports indent errors for blank lines in a function declaration - Squiz.Commenting.FunctionComment now corrects multi-line param comment padding more accurately - Squiz.Commenting.FunctionComment now properly fixes pipe-seperated param types - Squiz.Commenting.FunctionComment now works correctly when function return types also contain a comment