ezcode
ezcode

Reputation: 271

Difference between Sonar Complexity metric values and Complexity reporter by PMD

We are using Sonar to analyze our code and configured PMD, findbugs and checkstyle rules in a custom quality profile of Sonar. The PMD rule Code style cyclomatic complexity gathers the violations in our code if the threshold has been breached for this rule. Sonar also has a Complexity widget in the Project dashboard which displays complexity based on class, method and file. Does this Complexity widget consider the same rules defined by PMD rule engine for computing code style cyclomatic complexity or does this widget have its own way of calculating complexity? Does Sonar complexity widget use the violations reported by PMD rule engine in determining the complexity?

The reason for asking this question is, if both have different approaches of calculating complexity, then we would like to refer only one method and also which one is the best to keep.

Upvotes: 0

Views: 1033

Answers (1)

Sonar computes the cyclomatic complexity on its own using our internal Java parser. This is what gets displayed in the complexity widget. The computation may indeed differ from what PMD does. So if you activate the PMD rule about complexity, obviously this will be trigger against measures done by PMD, not by Sonar.

FYI, our goal is to progressively implement in Sonar (based on our own internal parser) most of the useful rules that can be found in PMD and in Checkstyle, so that there's no discrepancy in the main results like what you experienced.

Upvotes: 1

Related Questions