Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/Standards/Squiz/Sniffs/WhiteSpace/FunctionSpacingSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,15 +302,19 @@ public function process(File $phpcsFile, $stackPtr)

if ($foundLines < $requiredSpacing) {
$padding = str_repeat($phpcsFile->eolChar, ($requiredSpacing - $foundLines));
$phpcsFile->fixer->addContent($nextSpace, $padding);
$phpcsFile->fixer->addContentBefore($nextSpace, $padding);
} else {
$nextContent = $phpcsFile->findNext(T_WHITESPACE, ($nextSpace + 1), null, true);
$phpcsFile->fixer->beginChangeset();
for ($i = $nextSpace; $i < ($nextContent - 1); $i++) {
for ($i = $nextSpace; $i < $nextContent; $i++) {
if ($tokens[$i]['line'] === $tokens[$nextContent]['line']) {
$phpcsFile->fixer->addContentBefore($i, str_repeat($phpcsFile->eolChar, $requiredSpacing));
break;
}

$phpcsFile->fixer->replaceToken($i, '');
}

$phpcsFile->fixer->replaceToken($i, str_repeat($phpcsFile->eolChar, $requiredSpacing));
$phpcsFile->fixer->endChangeset();
}
}//end if
Expand Down
49 changes: 49 additions & 0 deletions src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,52 @@ $util->setLogger(new class {
function functionInEmbeddedPHP() {

}

// Make sure the indentation for the function comment does not get removed.
class MyClass
{

protected $tag = '';



/**
* Function comment.
*
* @return boolean
*/
function func1() {}

}//end class

class MyClass
{



/**
* Function comment.
*
* @return boolean
*/
function func1() {}

}//end class

class MyClass
{
// Unrelated comment.
/**
* Function comment.
*
* @return boolean
*/
function func1() {}
// phpcs:disable Standard.Category.Sniff -- for reasons.
/**
* Function comment.
*
* @return boolean
*/
function func2() {}
}//end class
Original file line number Diff line number Diff line change
Expand Up @@ -405,3 +405,52 @@ $util->setLogger(new class {
function functionInEmbeddedPHP() {

}

// Make sure the indentation for the function comment does not get removed.
class MyClass
{

protected $tag = '';

/**
* Function comment.
*
* @return boolean
*/
function func1() {}

}//end class

class MyClass
{

/**
* Function comment.
*
* @return boolean
*/
function func1() {}

}//end class

class MyClass
{
// Unrelated comment.

/**
* Function comment.
*
* @return boolean
*/
function func1() {}

// phpcs:disable Standard.Category.Sniff -- for reasons.

/**
* Function comment.
*
* @return boolean
*/
function func2() {}

}//end class
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public function getErrorList()
354 => 2,
355 => 1,
356 => 1,
379 => 1,
393 => 1,
405 => 2,
412 => 2,
];

}//end getErrorList()
Expand Down