How to improve Cyclomatic Complexity?

后端 未结 4 1356
野性不改
野性不改 2021-02-13 13:31

Cyclomatic Complexity will be high for methods with a high number of decision statements including if/while/for statements. So how do we improve on it?

I am handling a

4条回答
  •  执笔经年
    2021-02-13 14:03

    The last if in case 2 can be simplified:

     if(isTrue)
     {
      if(e > 1)
      {
    

    can be replaced by

    if(isTrue && (e>1))
    

    case 3 can be rewritten as:

    new string[]{StringConstants.AAA,...}
        .Contains(e.PropertyName)
    

    you can even make the string array into a HashSet to get O(1) performance.

提交回复
热议问题