Skip to content

Commit 3e18c86

Browse files
committed
Fixed bug #2601 : Squiz.WhiteSpace.FunctionSpacing incorrect fix when spacing is 0
1 parent 50d6208 commit 3e18c86

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
170170
- Fixed bug #2566 : Author tag email validation doesn't support all TLDs
171171
-- Thanks to Juliette Reinders Folmer for the patch
172172
- Fixed bug #2575 : Custom error messages don't have data replaced when cache is enabled
173+
- Fixed bug #2601 : Squiz.WhiteSpace.FunctionSpacing incorrect fix when spacing is 0
173174
</notes>
174175
<contents>
175176
<dir name="/">

src/Standards/Squiz/Sniffs/WhiteSpace/FunctionSpacingSniff.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,10 @@ public function process(File $phpcsFile, $stackPtr)
318318
$nextContent = $phpcsFile->findNext(T_WHITESPACE, ($nextSpace + 1), null, true);
319319
$phpcsFile->fixer->beginChangeset();
320320
for ($i = $nextSpace; $i < $nextContent; $i++) {
321+
if ($tokens[$i]['line'] === $tokens[$prevContent]['line']) {
322+
continue;
323+
}
324+
321325
if ($tokens[$i]['line'] === $tokens[$nextContent]['line']) {
322326
$phpcsFile->fixer->addContentBefore($i, str_repeat($phpcsFile->eolChar, $requiredSpacing));
323327
break;
@@ -327,7 +331,7 @@ public function process(File $phpcsFile, $stackPtr)
327331
}
328332

329333
$phpcsFile->fixer->endChangeset();
330-
}
334+
}//end if
331335
}//end if
332336
}//end if
333337

src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.1.inc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,3 +482,19 @@ class Foo {
482482
if (function_exists('foo') === false) {
483483
function foo(){}
484484
}
485+
486+
// phpcs:set Squiz.WhiteSpace.FunctionSpacing spacing 0
487+
// phpcs:set Squiz.WhiteSpace.FunctionSpacing spacingBeforeFirst 0
488+
// phpcs:set Squiz.WhiteSpace.FunctionSpacing spacingAfterLast 0
489+
490+
interface OneBlankLineBeforeFirstFunctionClassInterface
491+
{
492+
493+
494+
/** @return mixed */
495+
public function interfaceMethod();
496+
}
497+
498+
// phpcs:set Squiz.WhiteSpace.FunctionSpacing spacing 2
499+
// phpcs:set Squiz.WhiteSpace.FunctionSpacing spacingBeforeFirst 2
500+
// phpcs:set Squiz.WhiteSpace.FunctionSpacing spacingAfterLast 2

src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.1.inc.fixed

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,3 +566,17 @@ if (function_exists('foo') === false) {
566566

567567

568568
}
569+
570+
// phpcs:set Squiz.WhiteSpace.FunctionSpacing spacing 0
571+
// phpcs:set Squiz.WhiteSpace.FunctionSpacing spacingBeforeFirst 0
572+
// phpcs:set Squiz.WhiteSpace.FunctionSpacing spacingAfterLast 0
573+
574+
interface OneBlankLineBeforeFirstFunctionClassInterface
575+
{
576+
/** @return mixed */
577+
public function interfaceMethod();
578+
}
579+
580+
// phpcs:set Squiz.WhiteSpace.FunctionSpacing spacing 2
581+
// phpcs:set Squiz.WhiteSpace.FunctionSpacing spacingBeforeFirst 2
582+
// phpcs:set Squiz.WhiteSpace.FunctionSpacing spacingAfterLast 2

src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public function getErrorList($testFile='')
8787
478 => 2,
8888
479 => 1,
8989
483 => 2,
90+
495 => 1,
9091
];
9192

9293
case 'FunctionSpacingUnitTest.2.inc':

0 commit comments

Comments
 (0)