43 lines
1.1 KiB
Plaintext
43 lines
1.1 KiB
Plaintext
include::../intro.adoc[]
|
|
|
|
== Why is this an issue?
|
|
|
|
include::../why.adoc[]
|
|
|
|
=== What is the potential impact?
|
|
|
|
include::../impact.adoc[]
|
|
|
|
[source,vbnet,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
Function Abs(ByVal n As Integer) As Integer ' Noncompliant: cognitive complexity = 5
|
|
If n >= 0 Then ' +1
|
|
Return n
|
|
Else ' +2, due to nesting
|
|
If n = Integer.MinValue Then ' +1
|
|
Throw New ArgumentException("The absolute value of int.MinValue is outside of int boundaries")
|
|
Else ' +1
|
|
Return -n
|
|
End If
|
|
End If
|
|
End Function
|
|
----
|
|
|
|
They should be refactored to have lower complexity:
|
|
|
|
[source,vbnet,diff-id=1,diff-type=compliant]
|
|
----
|
|
Function Abs(ByVal n As Integer) As Integer ' Compliant: cognitive complexity = 3
|
|
If n = Integer.MinValue Then ' +1
|
|
Throw New ArgumentException("The absolute value of int.MinValue is outside of int boundaries")
|
|
Else If n >= 0 Then ' +1
|
|
Return n
|
|
Else ' +1
|
|
Return -n
|
|
End If
|
|
End Function
|
|
----
|
|
|
|
include::../resources.adoc[]
|
|
|
|
include::../rspecator-dotnet.adoc[] |