1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Fixture with known complexity values, used by integration tests.
# Cognitive: for(+1) + nested for(+2) + nested if(+3) + else(+1 flat) = 7
# Cyclomatic: base 1 + for + for + if = 4
# (Ruby has no labelled `next`, so the flat `else` supplies the 7th cognitive
# point that the other languages get from a labelled `continue`.)
total = 0
for i in 2..max
for j in 2...i
if i % j == 0
total += 0
else
total += i
end
end
end
total
end
# Cognitive: case(+1) = 1 ; Cyclomatic: base 1 + 2 non-default whens = 3
case n
when 1
when 2
else
end
end
# Cognitive: if(+1) + &&(+1) = 2 ; Cyclomatic: base 1 + if + && = 3
if a && b
return
end
end