From 1cbb4c09dffd4ce4c3c103a1f7a5035de2eb1132 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 20 Oct 2024 19:14:22 +0200 Subject: [PATCH] Generic/UnnecessaryHeredoc: add metrics This commit adds metrics to the new `Generic.Strings.UnnecessaryHeredoc` sniff to allow for collecting statistical information on how often a heredoc is used without expressions or interpolation. --- .../Generic/Sniffs/Strings/UnnecessaryHeredocSniff.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Standards/Generic/Sniffs/Strings/UnnecessaryHeredocSniff.php b/src/Standards/Generic/Sniffs/Strings/UnnecessaryHeredocSniff.php index 2f8cfa7cc6..0be0fde748 100644 --- a/src/Standards/Generic/Sniffs/Strings/UnnecessaryHeredocSniff.php +++ b/src/Standards/Generic/Sniffs/Strings/UnnecessaryHeredocSniff.php @@ -65,6 +65,7 @@ public function process(File $phpcsFile, $stackPtr) || $bodyToken[0] === T_VARIABLE ) { // Contains interpolation or expression. + $phpcsFile->recordMetric($stackPtr, 'Heredoc contains interpolation or expression', 'yes'); return; } @@ -73,9 +74,12 @@ public function process(File $phpcsFile, $stackPtr) && $tokenizedBody[($ptr + 1)] === '$' ) { // Contains interpolation or expression. + $phpcsFile->recordMetric($stackPtr, 'Heredoc contains interpolation or expression', 'yes'); return; } - } + }//end foreach + + $phpcsFile->recordMetric($stackPtr, 'Heredoc contains expression', 'no'); $warning = 'Detected heredoc without interpolation or expressions. Use nowdoc syntax instead';