Skip to content
Closed
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
15 changes: 7 additions & 8 deletions src/Standards/Squiz/Sniffs/WhiteSpace/FunctionSpacingSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,22 +262,21 @@ public function process(File $phpcsFile, $stackPtr)
$prevContent = $phpcsFile->findPrevious(T_WHITESPACE, ($tokens[$prevContent]['comment_opener'] - 1), null, true);
}

$prevLineToken = $prevContent;

// Before we throw an error, check that we are not throwing an error
// for another function. We don't want to error for no blank lines after
// the previous function and no blank lines before this one as well.
$prevLine = ($tokens[$prevContent]['line'] - 1);
$i = ($stackPtr - 1);
$foundLines = 0;

$stopAt = 0;
if (isset($tokens[$stackPtr]['conditions']) === true) {
$conditions = $tokens[$stackPtr]['conditions'];
if (isset($tokens[$prevLineToken]['conditions']) === true) {
$conditions = $tokens[$prevLineToken]['conditions'];
$conditions = array_keys($conditions);
$stopAt = array_pop($conditions);
}

$prevLineToken = $prevContent;
$prevLine = ($tokens[$prevContent]['line'] - 1);
$i = ($stackPtr - 1);
$foundLines = 0;

while ($currentLine !== $prevLine && $currentLine > 1 && $i > $stopAt) {
if ($tokens[$i]['code'] === T_FUNCTION) {
// Found another interface or abstract function.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,3 +574,11 @@ class ClassWithAttributes {
// phpcs:set Squiz.WhiteSpace.FunctionSpacing spacing 2
// phpcs:set Squiz.WhiteSpace.FunctionSpacing spacingBeforeFirst 2
// phpcs:set Squiz.WhiteSpace.FunctionSpacing spacingAfterLast 2

// Issue #3904.
echo 'this line belongs with the #3904 test';
class Person {public function __construct($name){}}
echo 'this line belongs with the #3904 test';

function Foo() {} function bar($name){}
echo 'this line belongs with the #3904 test';
Original file line number Diff line number Diff line change
Expand Up @@ -656,3 +656,18 @@ class ClassWithAttributes {
// phpcs:set Squiz.WhiteSpace.FunctionSpacing spacing 2
// phpcs:set Squiz.WhiteSpace.FunctionSpacing spacingBeforeFirst 2
// phpcs:set Squiz.WhiteSpace.FunctionSpacing spacingAfterLast 2

// Issue #3904.
echo 'this line belongs with the #3904 test';


class Person {public function __construct($name){}}


echo 'this line belongs with the #3904 test';


function Foo() {} function bar($name){}


echo 'this line belongs with the #3904 test';
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public function getErrorList($testFile='')
553 => 1,
560 => 1,
566 => 1,
580 => 2,
583 => 3,
];

case 'FunctionSpacingUnitTest.2.inc':
Expand Down