Why do I get high Cyclomatic complexity on simple POCO

Using Sonar Cloud we also keep an eye on Cyclomatic complexity of our code. In general this works fine but we do have some strange situations where simple POCO classes get a high score. Anyone an idea why? Both Visual Studio and the Rider CC plugin don’t see POCO classes as having a high Cyclomatic Complexity.

Hi,

You would need to post the code in question before anyone could give a coherent reply. In general, I’ll say that Cyclomatic Complexity can jump quite high quite quickly in some circumstances. Most notably, a switch with a lot of cases will seem to inflate the Cyclomatic Complexity score unreasonably.

This is one of several reasons we undertook the creation of Cognitive Complexity.

 
HTH,
Ann

Well, this class gives me a cyclomatic complexity of 24 for example:

public class ProjectIndex
{

    public int Id { get; set; }

    public string? Name { get; set; }

    public string? Street { get; set; }

    public int? HouseNumber { get; set; }

    public string? HouseNumberAddition { get; set; }

    public string? Zipcode { get; set; }

    public string? City { get; set; }

    public int? EstimatedAmountValue { get; set; }

    public int? Surface { get; set; }

    public int? BuildingPhaseId { get; set; }

    public string? BuildingPhase { get; set; }

    public Instant? StartedAt { get; set; }

}

Which imo makes no sense, and Rider also sees no issues:
image

Hi,

Cyclomatic Complexity increments for each method. Just having a method is +1.

You might want to take a look at the Cognitive Complexity score for the same class.

 
HTH,
Ann

The class only consists of only properties though. Unless you check the compiled “lower” c# code where the auto properties are converted to methods, but that wouldn’t make any sense.

Also, cognitive complexity is 0, which is as expected from a poco.
image