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 a9d0457
Showing 1 changed file with 5 additions and 1 deletion.
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 interpolation or expression', 'yes');
return;
}

Expand All @@ -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 interpolation or expression', 'no');

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

Expand Down

0 comments on commit a9d0457

Please sign in to comment.