From 1749d22cc113aa72cb9dab8b5db83ac2870f81f2 Mon Sep 17 00:00:00 2001 From: Michel Hunziker Date: Thu, 31 Dec 2015 13:33:48 +0100 Subject: [PATCH] Add total CRAP and percent CRAP --- README.md | 12 +++++++----- teamcity-clover.php | 5 ++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9ee91bc..7d49e1f 100644 --- a/README.md +++ b/README.md @@ -56,15 +56,17 @@ These values do not appear in the web interface by default, but can be used for ### CRAP Index ### PHPUnit calculates a Change Risk Anti-Patterns (CRAP) Index for each method, which depends on the cyclomatic complexity and code coverage (see [this question on StackOverflow](https://stackoverflow.com/q/4731774) for more information). -The script will report the average and maximum CRAP index to TeamCity, as well as the number of methods -with a CRAP index equal or above a specified threshold (by default 30). You can change the CRAP threshold -by providing the `--crap-threshold ` argument to the script. For example, to count all methods -with a CRAP index of 20 or more, use `php teamcity-clover.php --crap-threshold 20 clover.xml`. +The script will report the total, average, and maximum CRAP index to TeamCity, as well as the number and +percentage of methods with a CRAP index equal or above a specified threshold (by default 30). You can +change the CRAP threshold by providing the `--crap-threshold ` argument to the script. For example, +to count all methods with a CRAP index of 20 or more, use `php teamcity-clover.php --crap-threshold 20 clover.xml`. Set the threshold to 0 to disable the reporting of the CRAP metrics. Custom Statistic Key | Description ---------------------- | ------------------------------------------------------------- +--------------------- | ----------------------------------------------------------------- CRAPAmount | Number of methods with a CRAP index >= threshold (default: 30) +CRAPPercent | Percentage of methods with a CRAP index >= threshold (default: 30) +CRAPTotal | Total CRAP index (sum of all CRAP indices) CRAPAverage | Average CRAP index over all methods CRAPMaximum | Highest CRAP index reported diff --git a/teamcity-clover.php b/teamcity-clover.php index d3d9cc8..c123297 100644 --- a/teamcity-clover.php +++ b/teamcity-clover.php @@ -72,9 +72,12 @@ } $crapValuesCount = count($crapValues); + $crapTotal = array_sum($crapValues); $data['CRAPAmount'] = $crapAmount; - $data['CRAPAverage'] = $crapValuesCount ? array_sum($crapValues) / $crapValuesCount : 0; + $data['CRAPPercent'] = $crapValuesCount ? $crapAmount / $crapValuesCount * 100 : 0; + $data['CRAPTotal'] = $crapTotal; + $data['CRAPAverage'] = $crapValuesCount ? $crapTotal / $crapValuesCount : 0; $data['CRAPMaximum'] = max($crapValues); }