I'm developing an application that pulls data from an Excel file (I don't have access to the actual database) and I've written a method which has as its only function to pull the data from the Excel Spreadsheet, as seen below.
private IEnumerable<SMEntity> ExtractSMData(List<MSExcel.Range> SMData)
{
List<SMEntity> SMEntities = new List<SMEntity>();
foreach (MSExcel.Range Row in SMData)
{
SMEntity entity = new SMEntity();
entity.IncidentNumber = Row.get_Range("K1").get_Value();
entity.SRNumber = Row.get_Range("L1").get_Value();
entity.SRCategory = Row.get_Range("M1").get_Value();
entity.SiebelClientCall = EntityConversions.DateTimeConversion(Row.get_Range("N1").get_Value());
entity.SiebelOpenedDate = EntityConversions.DateTimeConversion(Row.get_Range("O1").get_Value());
entity.IncidentOpenDate = EntityConversions.DateTimeConversion(Row.get_Range("P1").get_Value());
entity.PickedUpBeforeClient = Row.get_Range("Q1").get_Value().ToString().ToLowerCase() == "no" ? false : true;
entity.OutageStartTime = EntityConversions.DateTimeConversion(Row.get_Range("R1").get_Value());
entity.DetectionPoint = EntityConversions.DateTimeConversion(Row.get_Range("S1").get_Value());
entity.SecondsToDetection = EntityConversions.ConvertDetectionTimeToInt(Row.get_Range("T1").get_Value());
entity.OutageEndTime = EntityConversions.DateTimeConversion(Row.get_Range("U1").get_Value());
entity.MTTR = EntityConversions.ConvertMTTRStringToInt(Row.get_Range("V1").get_Value());
entity.RepairedOnTime = Row.get_Range("W1").get_Value().ToString().ToLowerCase() == "no" ? false : true;
SMEntities.Add(entity);
}
return SMEntities;
}
I've run Code Analysis (I'm using Visual Studio 2012 and developing in .NET 4.5) and I have a CA1502: Avoid excessive complexity
(copied below). As a junior developer (I'm 17) I tried finding out more about this using MSDN however, I'm a little stumped as to why I have a cyclomatic complexity of 33.
CA1502
Avoid excessive complexity
'Extraction.ExtractSMData(List<Range>)'
has a cyclomatic complexity of 33. Rewrite or refactor the method to reduce complexity to 25.
Core.Extraction.cs:104
I can see with my quick-ifs (condition ? if_true : if_false
, what are these called?) that it might be bad, but I can still only see it as 5.
UPDATE:
Cyclomatic complexity is now at 33...
If I comment out entity.IncidentNumber = Row.get_Range("K1").get_Value();
the complexity becomes 32. I thought get_Range()
and get_Value()
were one each but okay...
If I comment out entity.RepairedOnTime = Row.get_Range("W1").get_Value().ToString().ToLower() == "no" ? false : true;
the complexity becomes 28...
get_Range()
, get_Value()
, quick-if is 3, do ToString()
and ToLower()
count?