Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic/OpeningFunctionBrace*: check spacing before brace for empty functions #3869

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
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,13 @@ public function process(File $phpcsFile, $stackPtr)
$ignore[] = T_WHITESPACE;
$next = $phpcsFile->findNext($ignore, ($openingBrace + 1), null, true);
if ($tokens[$next]['line'] === $tokens[$openingBrace]['line']) {
if ($next === $tokens[$stackPtr]['scope_closer']) {
// Ignore empty functions.
return;
}

$error = 'Opening brace must be the last content on the line';
$fix = $phpcsFile->addFixableError($error, $openingBrace, 'ContentAfterBrace');
if ($fix === true) {
$phpcsFile->fixer->addNewline($openingBrace);
// Only throw this error when this is not an empty function.
if ($next !== $tokens[$stackPtr]['scope_closer']) {
$error = 'Opening brace must be the last content on the line';
$fix = $phpcsFile->addFixableError($error, $openingBrace, 'ContentAfterBrace');
if ($fix === true) {
$phpcsFile->fixer->addNewline($openingBrace);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,15 @@ public function process(File $phpcsFile, $stackPtr)
$ignore[] = T_WHITESPACE;
$next = $phpcsFile->findNext($ignore, ($openingBrace + 1), null, true);
if ($tokens[$next]['line'] === $tokens[$openingBrace]['line']) {
if ($next === $tokens[$stackPtr]['scope_closer']
|| $tokens[$next]['code'] === T_CLOSE_TAG
// Only throw this error when this is not an empty function.
if ($next !== $tokens[$stackPtr]['scope_closer']
&& $tokens[$next]['code'] !== T_CLOSE_TAG
) {
// Ignore empty functions.
return;
}

$error = 'Opening brace must be the last content on the line';
$fix = $phpcsFile->addFixableError($error, $openingBrace, 'ContentAfterBrace');
if ($fix === true) {
$phpcsFile->fixer->addNewline($openingBrace);
$error = 'Opening brace must be the last content on the line';
$fix = $phpcsFile->addFixableError($error, $openingBrace, 'ContentAfterBrace');
if ($fix === true) {
$phpcsFile->fixer->addNewline($openingBrace);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,10 @@ class Issue3357WithComment
// code here.
}
}

function myFunction()
{}
function myFunction()
{} // Too many spaces indent with an empty function.
function myFunction()
{} // Too little spaces indent with an empty function.
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,10 @@ class Issue3357WithComment
// code here.
}
}

function myFunction()
{}
function myFunction()
{} // Too many spaces indent with an empty function.
function myFunction()
{} // Too little spaces indent with an empty function.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public function getErrorList()
244 => 1,
252 => 1,
260 => 1,
268 => 1,
270 => 1,
];

}//end getErrorList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,7 @@ function myFunction($a, $lot, $of, $params)
: array { // phpcs:ignore Standard.Category.Sniff -- for reasons.
return null;
}

function myFunction() {}
function myFunction() {} // Too many spaces with an empty function.
function myFunction() {} // Too many spaces (tab) with an empty function.
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,7 @@ function myFunction($a, $lot, $of, $params)
: array { // phpcs:ignore Standard.Category.Sniff -- for reasons.
return null;
}

function myFunction() {}
function myFunction() {} // Too many spaces with an empty function.
function myFunction() {} // Too many spaces (tab) with an empty function.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public function getErrorList()
191 => 1,
197 => 1,
203 => 1,
213 => 1,
214 => 1,
];

}//end getErrorList()
Expand Down