As per Wiki:
Cyclomatic complexity is a software metric, used to indicate the complexity of a program. It is a quantitative measure of the number of linearly independent paths through a program's source code. It was developed by Thomas J. McCabe, Sr. in 1976.
Could this term apply to C# Linq with a lambda expression like this one:
_fred = fred.Where(c =>
c.IsActive &&
c.PriorityOrder.HasValue &&
(c.PriorityOrder == 0 || !(c.MinUnits == 0 && (!c.MaxUnits.HasValue || c.MaxUnits == 0))))
.GroupBy(x => x.Scope)
.ToDictionary(x => x.Key, x => x.ToList());
if so, what is the cyclomatic complexity
of this bit of code and why does Resharper tells me it is.. 1?
Same piece of logic from the Where
clause above broken down into multiple if
statements shows cyclomatic complexity of 9. Why?
private IEnumerable<Priority> FilterPriorities(IEnumerable<Priority> priorities)
{
var result = new List<Priority>();
foreach (var p in priorities)
{
if (p.IsActive == false) continue;
if (p.PriorityOrder.HasValue == false) continue;
if (p.PriorityOrder == 0)
{
result.Add(p);
continue;
}
if ((p.MinUnits == 0 && (!p.MaxUnits.HasValue || p.MaxUnits == 0)) == false)
{
result.Add(p);
}
}
return result;
}