Skip to content

Commit

Permalink
The "Function opening brace placement" metric has been separated into…
Browse files Browse the repository at this point in the history
… function and closure metrics in the info report
  • Loading branch information
gsherwood committed Mar 6, 2018
1 parent fcf1079 commit 281e44b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
3 changes: 3 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ http://pear.php.net/dtd/package-2.0.xsd">
-- Thanks to Timo Schinkel for the patch
- The key used for caching PHPCS runs now includes all set config values
-- This fixes a problem where changing config values (e.g., via --runtime-set) used an incorrect cache file
- The "Function opening brace placement" metric has been separated into function and closure metrics in the info report
-- Closures are no longer included in the "Function opening brace placement" metric
-- A new "Closure opening brace placement" metric now shows information for closures
- Added new Generic.WhiteSpace.ArbitraryParenthesesSpacing sniff
-- Generates an error for whitespace inside parenthesis that don't belong to a function call/declaration or control structure
-- Generates a warning for any empty parenthesis found
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public function process(File $phpcsFile, $stackPtr)

$lineDifference = ($braceLine - $functionLine);

$metricType = 'Function';
if ($tokens[$stackPtr]['code'] === T_CLOSURE) {
$metricType = 'Closure';
}

if ($lineDifference === 0) {
$error = 'Opening brace should be on a new line';
$fix = $phpcsFile->addFixableError($error, $openingBrace, 'BraceOnSameLine');
Expand All @@ -99,7 +104,7 @@ public function process(File $phpcsFile, $stackPtr)
$phpcsFile->fixer->endChangeset();
}

$phpcsFile->recordMetric($stackPtr, 'Function opening brace placement', 'same line');
$phpcsFile->recordMetric($stackPtr, "$metricType opening brace placement", 'same line');
} else if ($lineDifference > 1) {
$error = 'Opening brace should be on the line after the declaration; found %s blank line(s)';
$data = [($lineDifference - 1)];
Expand Down Expand Up @@ -167,7 +172,7 @@ public function process(File $phpcsFile, $stackPtr)
}
}//end if

$phpcsFile->recordMetric($stackPtr, 'Function opening brace placement', 'new line');
$phpcsFile->recordMetric($stackPtr, "$metricType opening brace placement", 'new line');

}//end process()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,13 @@ public function process(File $phpcsFile, $stackPtr)

$lineDifference = ($braceLine - $functionLine);

$metricType = 'Function';
if ($tokens[$stackPtr]['code'] === T_CLOSURE) {
$metricType = 'Closure';
}

if ($lineDifference > 0) {
$phpcsFile->recordMetric($stackPtr, 'Function opening brace placement', 'new line');
$phpcsFile->recordMetric($stackPtr, "$metricType opening brace placement", 'new line');
$error = 'Opening brace should be on the same line as the declaration';
$fix = $phpcsFile->addFixableError($error, $openingBrace, 'BraceOnNewLine');
if ($fix === true) {
Expand Down Expand Up @@ -116,7 +121,7 @@ public function process(File $phpcsFile, $stackPtr)
$phpcsFile->fixer->endChangeset();
}//end if
} else {
$phpcsFile->recordMetric($stackPtr, 'Function opening brace placement', 'same line');
$phpcsFile->recordMetric($stackPtr, "$metricType opening brace placement", 'same line');
}//end if

$next = $phpcsFile->findNext(T_WHITESPACE, ($openingBrace + 1), null, true);
Expand Down

0 comments on commit 281e44b

Please sign in to comment.