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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ The file documents changes to the PHP_CodeSniffer project.
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Sniff error messages are now more informative to help bugs get reported to the correct project
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Generic.Functions.OpeningFunctionBraceBsdAllman will now check the brace indent before the opening brace for empty functions
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Generic.Functions.OpeningFunctionBraceKernighanRitchie will now check the spacing before the opening brace for empty functions
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- PSR2.Classes.PropertyDeclaration now enforces that the readonly modifier comes after the visibility modifier
- PSR2 and PSR12 do not have documented rules for this as they pre-date the readonly modifier
- PSR-PER has been used to confirm the order of this keyword so it can be applied to PSR2 and PSR12 correctly
Expand Down
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