Note that there are some explanatory texts on larger screens.

plurals
  1. POwhy would I refactor this code as Cyclomatic Complexity is 58
    primarykey
    data
    text
    <p>I read that having CC 10 or less would be highly maintainable code. But the method that I wrote have CC 58. Thanks to VS 2010 code analysis tool. I believe that the method I wrote is very simple, readable and maintainable as far as my understanding. Hence I would not prefer refactoring the code. But since CC is higher than acceptable, I am wondering why would one refactor this method. I am learning things to improve my code If I have mistake, plese correct me. Here is the code. </p> <pre><code>private string MapBathRooms(string value) { double retValue = 0; if (value == "1" || value == "One") retValue = 1; if (value == "OneAndHalf" || value == "1.5" || value == "1 1/2") retValue = 1.5; if (value == "2" || value == "Two") retValue = 2; if (value == "TwoAndHalf" || value == "2.5" || value == "2 1/2") retValue = 2.5; if (value == "3" || value == "Three") retValue = 3; if (value == "ThreeAndHalf" || value == "3.5" || value == "3 1/2") retValue = 3.5; if (value == "4" || value == "Four") retValue = 4; if (value == "FourAndHalf" || value == "4.5" || value == "4 1/2") retValue = 4.5; if (value == "5" || value == "Five" || value == "FourOrMore") retValue = 5; if (value == "FiveAndHalf" || value == "5.5" || value == "5 1/2") retValue = 5.5; if (value == "6" || value == "Six") retValue = 6; if (value == "SixAndHalf" || value == "6.5" || value == "6 1/2") retValue = 6.5; if (value == "7" || value == "Seven") retValue = 7; if (value == "SevenAndHalf" || value == "7.5" || value == "7 1/2") retValue = 7.5; if (value == "8" || value == "8+" || value == "Eight" || value == "SevenOrMore") retValue = 8; if (value == "EightAndHalf" || value == "8.5" || value == "8 1/2") retValue = 8.5; if (value == "9" || value == "Nine") retValue = 9; if (value == "NineAndHalf" || value == "9.5" || value == "9 1/2") retValue = 9.5; if(value == "10" || value == "Ten") retValue = 10; if (value == "TenAndHalf" || value == "10.5" || value == "10 1/2" || value == "10+" || value == "MoreThanTen" || value == "11") retValue = 10.5; if (retValue == 0) return value; return retValue.ToString(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload