Skip to content
This repository has been archived by the owner on May 13, 2021. It is now read-only.

Commit

Permalink
Add total CRAP and percent CRAP
Browse files Browse the repository at this point in the history
  • Loading branch information
micheh committed Dec 31, 2015
1 parent 6703605 commit 1749d22
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <number>` 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 <number>` 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

Expand Down
5 changes: 4 additions & 1 deletion teamcity-clover.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 1749d22

Please sign in to comment.