diff --git a/package.xml b/package.xml index 10fa862849..b621f14dc4 100644 --- a/package.xml +++ b/package.xml @@ -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 diff --git a/src/Standards/Generic/Sniffs/Functions/OpeningFunctionBraceBsdAllmanSniff.php b/src/Standards/Generic/Sniffs/Functions/OpeningFunctionBraceBsdAllmanSniff.php index 3e4b9f936d..73cecacdfd 100644 --- a/src/Standards/Generic/Sniffs/Functions/OpeningFunctionBraceBsdAllmanSniff.php +++ b/src/Standards/Generic/Sniffs/Functions/OpeningFunctionBraceBsdAllmanSniff.php @@ -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'); @@ -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)]; @@ -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() diff --git a/src/Standards/Generic/Sniffs/Functions/OpeningFunctionBraceKernighanRitchieSniff.php b/src/Standards/Generic/Sniffs/Functions/OpeningFunctionBraceKernighanRitchieSniff.php index ca6eb7f395..d93be01427 100644 --- a/src/Standards/Generic/Sniffs/Functions/OpeningFunctionBraceKernighanRitchieSniff.php +++ b/src/Standards/Generic/Sniffs/Functions/OpeningFunctionBraceKernighanRitchieSniff.php @@ -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) { @@ -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);