2023-10-20 17:10:07 +02:00
|
|
|
include::../intro.adoc[]
|
|
|
|
|
2023-06-16 15:42:52 +02:00
|
|
|
== Why is this an issue?
|
2021-09-20 15:38:42 +02:00
|
|
|
|
2023-10-20 17:10:07 +02:00
|
|
|
include::../why.adoc[]
|
|
|
|
|
|
|
|
=== What is the potential impact?
|
2021-09-20 15:38:42 +02:00
|
|
|
|
2023-10-20 17:10:07 +02:00
|
|
|
include::../impact.adoc[]
|
2021-09-20 15:38:42 +02:00
|
|
|
|
2023-06-16 15:42:52 +02:00
|
|
|
[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
|
|
|
|
----
|
2021-09-20 15:38:42 +02:00
|
|
|
|
2023-06-16 15:42:52 +02:00
|
|
|
They should be refactored to have lower complexity:
|
2021-09-20 15:38:42 +02:00
|
|
|
|
2023-06-16 15:42:52 +02:00
|
|
|
[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[]
|
2023-06-22 10:38:01 +02:00
|
|
|
|
2023-06-16 15:42:52 +02:00
|
|
|
include::../rspecator-dotnet.adoc[]
|