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
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,37 @@ public function process(File $phpcsFile, $stackPtr)
$error = 'Opening brace should be on a new line';
$fix = $phpcsFile->addFixableError($error, $openingBrace, 'BraceOnSameLine');
if ($fix === true) {
$hasTrailingAnnotation = false;
for ($nextLine = ($openingBrace + 1); $nextLine < $phpcsFile->numTokens; $nextLine++) {
if ($tokens[$openingBrace]['line'] !== $tokens[$nextLine]['line']) {
break;
}

if (isset(Tokens::$phpcsCommentTokens[$tokens[$nextLine]['code']]) === true) {
$hasTrailingAnnotation = true;
}
}

$phpcsFile->fixer->beginChangeset();
$indent = $phpcsFile->findFirstOnLine([], $openingBrace);
if ($tokens[$indent]['code'] === T_WHITESPACE) {
$phpcsFile->fixer->addContentBefore($openingBrace, $tokens[$indent]['content']);

if ($hasTrailingAnnotation === false || $nextLine === false) {
if ($tokens[$indent]['code'] === T_WHITESPACE) {
$phpcsFile->fixer->addContentBefore($openingBrace, $tokens[$indent]['content']);
}

$phpcsFile->fixer->addNewlineBefore($openingBrace);
} else {
$phpcsFile->fixer->replaceToken($openingBrace, '');
$phpcsFile->fixer->addNewlineBefore($nextLine);
$phpcsFile->fixer->addContentBefore($nextLine, '{');
if ($tokens[$indent]['code'] === T_WHITESPACE) {
$phpcsFile->fixer->addContentBefore($nextLine, $tokens[$indent]['content']);
}
}

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

$phpcsFile->recordMetric($stackPtr, "$metricType opening brace placement", 'same line');
} else if ($lineDifference > 1) {
Expand All @@ -125,7 +147,9 @@ public function process(File $phpcsFile, $stackPtr)
}
}//end if

$next = $phpcsFile->findNext(T_WHITESPACE, ($openingBrace + 1), null, true);
$ignore = Tokens::$phpcsCommentTokens;
$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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ public function process(File $phpcsFile, $stackPtr)
$phpcsFile->recordMetric($stackPtr, "$metricType opening brace placement", 'same line');
}//end if

$next = $phpcsFile->findNext(T_WHITESPACE, ($openingBrace + 1), null, true);
$ignore = Tokens::$phpcsCommentTokens;
$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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,23 @@ function myFunction($a, $lot, $of, $params)
: array {
return null;
}

function myFunction($a, $lot, $of, $params) { // comment
return null;
}

function myFunction($a, $lot, $of, $params)
: array { // comment
return null;
}

function myFunction($a, $lot, $of, $params)
: array { // phpcs:ignore Standard.Category.Sniff -- for reasons.
return null;
}

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

function myFunction($a, $lot, $of, $params)
{
// comment
return null;
}

function myFunction($a, $lot, $of, $params)
: array
{
// comment
return null;
}

function myFunction($a, $lot, $of, $params)
: array // phpcs:ignore Standard.Category.Sniff -- for reasons.
{
return null;
}

function myFunction($a, $lot, $of, $params)
: array
{ // phpcs:ignore Standard.Category.Sniff -- for reasons.
return null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public function getErrorList()
176 => 1,
196 => 1,
201 => 1,
205 => 2,
210 => 2,
215 => 1,
];

}//end getErrorList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,8 @@ function myFunction($a, $lot, $of, $params)
{
return null;
}

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

function myFunction($a, $lot, $of, $params)
: array {
// phpcs:ignore Standard.Category.Sniff -- for reasons.
: array { // phpcs:ignore Standard.Category.Sniff -- for reasons.
return null;
}

function myFunction($a, $lot, $of, $params)
: array { // phpcs:ignore Standard.Category.Sniff -- for reasons.
return null;
}