I have a question regarding Cyclometric Complexity.

I'm looking to include a number of metrics in my Browse and Doc It plug-in and I've been researching the above (wikipedia and the metric notes in RAD Studio) and they mention IF statement and later on conditional loops but they are silent on CASE statements.

If an IF statement increases the complexity by 1 should a CASE statement increase the complexity by at least 1 if not more due to the number of branches?

I'm looking to include a number of metrics in my Browse and Doc It plug-in and I've been researching the above (wikipedia and the metric notes in RAD Studio) and they mention IF statement and later on conditional loops but they are silent on CASE statements.

If an IF statement increases the complexity by 1 should a CASE statement increase the complexity by at least 1 if not more due to the number of branches?

- 1d
- See mccabe.com - www.mccabe.com/pdf/mccabe-nist235r.pdf and the link from which I got this original source ...

https://stackoverflow.com/questions/30240236/cyclomatic-complexity-of-switch-case-statement

... as I understand it ...

McCabes CC counted case fallthroughs as 1 - and every case also as 1

So IMO ...

procedure TForm3.CC;

var

number: Integer;

begin

number := 17;

Case number mod 2 of

0:

ShowMessage(IntToStr(number) + ' mod 2 = 0');

1:

ShowMessage(IntToStr(number) + ' mod 2 = 1');

else

ShowMessage(IntToStr(number) + ' mod 2 is unknown');

end;

end;

... should have a CC of 3 - which it has not in Delphi ... where it has 2 ... which seems to be aligned with the more modern way of counting, where the fallthrough is not counted :-)1d - +Roland Kossow thank for the links my google foo last night and this morning completely fail. In your example the case statement has a CC of 3 (which I agree with) but the method 4 as an empty method should have a CC of 1. I’ll read the PDF.23h
- +David Hoyle yw - ok - this (method 4) is not the way Delphi calculates the CC - according to my quick test.23h
- I understand the principles I might have to look at some configurable sub options. Thanks again for the links.23h
- /sub23h
- /interested20h