10

In Sonar, for a particular Java class, I see :

Complexity:     830

Complexity /method:     8,1

How could you explain the difference between those two metrics ?

Is "Complexity" the class complexity ?

What is the maximum complexity a class should be under ? I know methods should be less than 10 for method complexity, but what is the maximum class complexity number a class should conform to be considered not complex ?

Thanks.

EDIT

I also look at Cyclomatic-Complexity rule violations in the file.

For a number of methods, sonar says with different complexity numbers (in french) :

"La complexité cyclomatique de la classe est de 28 alors que le maximum autorisé est de 10."

in english :

"The class cyclomatic complexity is 28 but the maximum allowed is 10".

I don't understand why it says "class cyclomatic complexity" as it seems as a "method cyclomatic complexity".

Also, the class in question does not appears on top of the most complex class sorted by average complexity/method, as sonar says it has only 8,1 average method complexity.

Farvardin
  • 5,336
  • 5
  • 33
  • 54
Jérôme Radix
  • 10,285
  • 4
  • 34
  • 40

1 Answers1

6

You can have a look at our "Metric Definitions" Wiki page (and more specifically on the "Complexity" section) to know more about the meaning of metrics found in Sonar.

  • "Complexity" is the total complexity of a resource (for a file => sum of the complexities of every class defined in the file)
  • "Complexity / method" is the "Complexity" divided by the number of methods found in the file
  • ... and so on for the other metrics.
Olivier
  • 3,465
  • 2
  • 23
  • 26
  • 1
    Thanks for your answer. Perhaps it is me but it was not that obvious that "Complexity" means "sum of methods complexities", but now it seems obvious indeed. The wiki page does not state that it is the sum of all methods complexities. – Jérôme Radix Apr 26 '12 at 07:19
  • @Jérôme: Officially, the sum of McCabe's complexities for a class is called WMC (Weighted Methods per Class) as described [here](https://sonarqube.sourcemeter.com/plugins/resource/491408?page=sm-help#Complexity). – Tibor Bakota - FrontEndART Aug 14 '14 at 12:40
  • the link presented does not differentiate among the complexity metrics that sonar handle: like CoreMetrics.FILE_COMPLEXITY and CoreMetrics.COMPLEXITY – XtianGIS Oct 04 '16 at 23:47