resharper-cyclomatic-complexity icon indicating copy to clipboard operation
resharper-cyclomatic-complexity copied to clipboard

Specific keywords like try and finally are adding to the Cyclomatic Complexity that should not

Open CreepyGnome opened this issue 7 years ago • 1 comments

The CC does not appear to be calculating correctly. Below are two pairs of arbitrary methods to simplify the issue In pair 1 they should both be CC = 2 and in Pair 2 they should be CC = 1.

It appears that the Try and Finally are adding to the CC when they should be ignored. These pair of methods are identical within the pair and should have the same CC.

My understanding in CC is that at the least the following keywords are ignored:

else, do, switch, try, using, throw, finally, return

I didn't check all of them but found two and stopped as it should be easy enough for you guys to work out the rest.

// PAIR 1
// R# Ext CC = 2
private static string DoSomething1(string value)
{
    if (string.IsNullOrEmpty(value))
        value.ToString();

    return value;
}
// R# Ext CC = 6
private static string DoSomething2(string value)
{
    try
    {
        return value;
    }
    finally
    {
        if (string.IsNullOrEmpty(value))
            value.ToString();
    }
}
// PAIR 2
// R# Ext CC = 1
private static void DoSomething3()
{
            
}
// R# Ext CC = 3
private static void DoSomething4()
{
    try
    {
                
    }
    finally
    {
                
    }
}

CreepyGnome avatar Nov 27 '17 19:11 CreepyGnome

For C# I suggest checking out https://github.com/matkoch/resharper-cognitivecomplexity

matkoch avatar May 01 '20 14:05 matkoch