Skip to content

Commit

Permalink
Generic/UnnecessaryHeredoc: add metrics
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jrfnl committed Oct 20, 2024
1 parent 6995755 commit d720467
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function process(File $phpcsFile, $stackPtr)
|| $bodyToken[0] === T_VARIABLE
) {
// Contains interpolation or expression.
$phpcsFile->recordMetric($stackPtr, 'Heredoc contains expression', 'yes');
return;
}

Expand All @@ -73,10 +74,13 @@ public function process(File $phpcsFile, $stackPtr)
&& $tokenizedBody[($ptr + 1)] === '$'
) {
// Contains interpolation or expression.
$phpcsFile->recordMetric($stackPtr, 'Heredoc contains expression', 'yes');
return;
}
}

$phpcsFile->recordMetric($stackPtr, 'Heredoc contains expression', 'no');

$warning = 'Detected heredoc without interpolation or expressions. Use nowdoc syntax instead';

$fix = $phpcsFile->addFixableWarning($warning, $stackPtr, 'Found');
Expand Down

0 comments on commit d720467

Please sign in to comment.