diff --git a/package.xml b/package.xml index 7640bfc256..2f0f72bfb9 100644 --- a/package.xml +++ b/package.xml @@ -170,6 +170,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> - Fixed bug #2566 : Author tag email validation doesn't support all TLDs -- Thanks to Juliette Reinders Folmer for the patch - Fixed bug #2575 : Custom error messages don't have data replaced when cache is enabled + - Fixed bug #2601 : Squiz.WhiteSpace.FunctionSpacing incorrect fix when spacing is 0 diff --git a/src/Standards/Squiz/Sniffs/WhiteSpace/FunctionSpacingSniff.php b/src/Standards/Squiz/Sniffs/WhiteSpace/FunctionSpacingSniff.php index c048ae3d96..264dc99552 100644 --- a/src/Standards/Squiz/Sniffs/WhiteSpace/FunctionSpacingSniff.php +++ b/src/Standards/Squiz/Sniffs/WhiteSpace/FunctionSpacingSniff.php @@ -318,6 +318,10 @@ public function process(File $phpcsFile, $stackPtr) $nextContent = $phpcsFile->findNext(T_WHITESPACE, ($nextSpace + 1), null, true); $phpcsFile->fixer->beginChangeset(); for ($i = $nextSpace; $i < $nextContent; $i++) { + if ($tokens[$i]['line'] === $tokens[$prevContent]['line']) { + continue; + } + if ($tokens[$i]['line'] === $tokens[$nextContent]['line']) { $phpcsFile->fixer->addContentBefore($i, str_repeat($phpcsFile->eolChar, $requiredSpacing)); break; @@ -327,7 +331,7 @@ public function process(File $phpcsFile, $stackPtr) } $phpcsFile->fixer->endChangeset(); - } + }//end if }//end if }//end if diff --git a/src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.1.inc b/src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.1.inc index a158fc43ed..c49e98f338 100644 --- a/src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.1.inc +++ b/src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.1.inc @@ -482,3 +482,19 @@ class Foo { if (function_exists('foo') === false) { function foo(){} } + +// phpcs:set Squiz.WhiteSpace.FunctionSpacing spacing 0 +// phpcs:set Squiz.WhiteSpace.FunctionSpacing spacingBeforeFirst 0 +// phpcs:set Squiz.WhiteSpace.FunctionSpacing spacingAfterLast 0 + +interface OneBlankLineBeforeFirstFunctionClassInterface +{ + + + /** @return mixed */ + public function interfaceMethod(); +} + +// phpcs:set Squiz.WhiteSpace.FunctionSpacing spacing 2 +// phpcs:set Squiz.WhiteSpace.FunctionSpacing spacingBeforeFirst 2 +// phpcs:set Squiz.WhiteSpace.FunctionSpacing spacingAfterLast 2 diff --git a/src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.1.inc.fixed b/src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.1.inc.fixed index ab0282a0c8..74f085d868 100644 --- a/src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.1.inc.fixed +++ b/src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.1.inc.fixed @@ -566,3 +566,17 @@ if (function_exists('foo') === false) { } + +// phpcs:set Squiz.WhiteSpace.FunctionSpacing spacing 0 +// phpcs:set Squiz.WhiteSpace.FunctionSpacing spacingBeforeFirst 0 +// phpcs:set Squiz.WhiteSpace.FunctionSpacing spacingAfterLast 0 + +interface OneBlankLineBeforeFirstFunctionClassInterface +{ + /** @return mixed */ + public function interfaceMethod(); +} + +// phpcs:set Squiz.WhiteSpace.FunctionSpacing spacing 2 +// phpcs:set Squiz.WhiteSpace.FunctionSpacing spacingBeforeFirst 2 +// phpcs:set Squiz.WhiteSpace.FunctionSpacing spacingAfterLast 2 diff --git a/src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.php b/src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.php index a674ffc063..7251319974 100644 --- a/src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.php +++ b/src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.php @@ -87,6 +87,7 @@ public function getErrorList($testFile='') 478 => 2, 479 => 1, 483 => 2, + 495 => 1, ]; case 'FunctionSpacingUnitTest.2.inc':