From a0b5bce9c3561eb4678106aa19a19a2c51e290f1 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 15 Aug 2019 00:43:41 +0200 Subject: [PATCH] Squiz/FunctionSpacing + MemberVarSpacing: add metrics 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. --- .../Squiz/Sniffs/WhiteSpace/FunctionSpacingSniff.php | 10 ++++++++++ .../Squiz/Sniffs/WhiteSpace/MemberVarSpacingSniff.php | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/src/Standards/Squiz/Sniffs/WhiteSpace/FunctionSpacingSniff.php b/src/Standards/Squiz/Sniffs/WhiteSpace/FunctionSpacingSniff.php index f4be5aa986..c048ae3d96 100644 --- a/src/Standards/Squiz/Sniffs/WhiteSpace/FunctionSpacingSniff.php +++ b/src/Standards/Squiz/Sniffs/WhiteSpace/FunctionSpacingSniff.php @@ -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) { @@ -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) { diff --git a/src/Standards/Squiz/Sniffs/WhiteSpace/MemberVarSpacingSniff.php b/src/Standards/Squiz/Sniffs/WhiteSpace/MemberVarSpacingSniff.php index 1f241e3b13..457a3ba834 100644 --- a/src/Standards/Squiz/Sniffs/WhiteSpace/MemberVarSpacingSniff.php +++ b/src/Standards/Squiz/Sniffs/WhiteSpace/MemberVarSpacingSniff.php @@ -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;