Skip to content

Commit

Permalink
Fixed bug #2601 : Squiz.WhiteSpace.FunctionSpacing incorrect fix when…
Browse files Browse the repository at this point in the history
… spacing is 0
  • Loading branch information
gsherwood committed Sep 9, 2019
1 parent 50d6208 commit 3e18c86
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
</notes>
<contents>
<dir name="/">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -327,7 +331,7 @@ public function process(File $phpcsFile, $stackPtr)
}

$phpcsFile->fixer->endChangeset();
}
}//end if
}//end if
}//end if

Expand Down
16 changes: 16 additions & 0 deletions src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.1.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public function getErrorList($testFile='')
478 => 2,
479 => 1,
483 => 2,
495 => 1,
];

case 'FunctionSpacingUnitTest.2.inc':
Expand Down

0 comments on commit 3e18c86

Please sign in to comment.