Skip to content

Commit

Permalink
Squiz/FunctionSpacing + MemberVarSpacing: add metrics
Browse files Browse the repository at this point in the history
For repos not yet using these sniffs, having metrics available will be useful to find out what the prevalent number of blank lines between properties/functions is.

This will make it more easy to determine what to set for the value of the various properties available.
  • Loading branch information
jrfnl committed Aug 14, 2019
1 parent 74ff74d commit a0b5bce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Standards/Squiz/Sniffs/WhiteSpace/FunctionSpacingSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ public function process(File $phpcsFile, $stackPtr)
}
}

if ($isLast === true) {
$phpcsFile->recordMetric($stackPtr, 'Function spacing after last', $foundLines);
} else {
$phpcsFile->recordMetric($stackPtr, 'Function spacing after', $foundLines);
}

if ($foundLines !== $requiredSpacing) {
$error = 'Expected %s blank line';
if ($requiredSpacing !== 1) {
Expand Down Expand Up @@ -280,6 +286,10 @@ public function process(File $phpcsFile, $stackPtr)
if ($isFirst === true) {
$requiredSpacing = $this->spacingBeforeFirst;
$errorCode = 'BeforeFirst';

$phpcsFile->recordMetric($stackPtr, 'Function spacing before first', $foundLines);
} else {
$phpcsFile->recordMetric($stackPtr, 'Function spacing before', $foundLines);
}

if ($foundLines !== $requiredSpacing) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ protected function processMemberVar(File $phpcsFile, $stackPtr)
}

$foundLines = ($tokens[$first]['line'] - $tokens[$prev]['line'] - 1);

if ($errorCode === 'FirstIncorrect') {
$phpcsFile->recordMetric($stackPtr, 'Member var spacing before first', $foundLines);
} else {
$phpcsFile->recordMetric($stackPtr, 'Member var spacing before', $foundLines);
}

if ($foundLines === $spacing) {
if ($endOfStatement !== false) {
return $endOfStatement;
Expand Down

0 comments on commit a0b5bce

Please sign in to comment.