Flow complexity (ARCH714)
هذا المحتوى غير متوفر بلغتك بعد.
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.
Incorrect
Section titled “Incorrect”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); } } } }}Correct
Section titled “Correct”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);}