Zum Inhalt springen

Flow complexity (ARCH714)

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Key dotnet.codequality.flow-complexity · Severity warning · Category codequality

Flags a method whose branches and loops are nested so deeply that a reader has to keep several conditions in mind at once. Each if, loop, catch, switch and ternary costs one plus one per level it is nested at; else and else-if cost one; a run of the same && or || costs one; a method calling itself costs one. Reported above 15.

foreach (var order in orders)
{
if (order.IsPaid)
{
foreach (var line in order.Lines)
{
if (line.Stock > 0 && line.Active)
{
try { Ship(line); }
catch (Exception) { if (retry) Queue(line); else Fail(line); }
}
}
}
}
foreach (var order in orders.Where(o => o.IsPaid))
ShipLines(order);
void ShipLines(Order order)
{
foreach (var line in order.Lines.Where(IsShippable))
TryShip(line);
}