Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
CreepyGnome opened this issue Nov 27, 2017 · 1 comment

Comments

@CreepyGnome
Copy link

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
    {
                
    }
}
@matkoch
Copy link
Member

matkoch commented May 1, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants