Questions tagged [cyclomatic-complexity]
Cyclomatic complexity is a number used to express the complexity of source code (e.g. of a method). It is calculated based on the number of different possible paths through the source code. Low cyclomatic complexity is one factor to improve readability, maintainability, and testability of code.
cyclomatic-complexity
291
questions
0
votes
0
answers
6
views
PMD Cyclomatic Complexity Causing Problem - Can I Disable?
I'm running a Gradle (Kotlin) build in Java, and overall it's going well. However, the PMD report is set to automatically stop the build if the cyclomatic complexity is 5 or more. This hasn't been too ...
0
votes
2
answers
294
views
Cyclomatic complexity of a for loop
I've been introduced to the cyclomatic complexity with two different definitions. First "the cyclomatic complexity is the number of independent paths in the flux diagram of the code" and ...
0
votes
1
answer
92
views
How to set cyclomatic complexity limit for specific method?
We have a codebase which is 20 years old running on .NET framework 4.8, and we have a requirement to add a code analyzer to a check for cyclomatic complexity in our source code and fail a build ...
1
vote
0
answers
64
views
How can I get the cyclomatic complexity by method of a collection of Javascript files?
I want to programmatically extract the cyclomatic complexity of all methods in a javascript project.
I know eslint can do this, but the project already has an _eslintrc.json defined, and I would like ...
1
vote
1
answer
577
views
Build flag added to the configuration and causes pipeline fail
I am using STM32CubeIDE which is based on eclipse.
The problem is that a flag is added and don't know how it was added it is called -fcyclomatic-complexity.
It causes the inclusion of .cyclo files. ...
2
votes
1
answer
212
views
Why is the Strategy design pattern applicable when reducing the cyclomatic complexity of the code?
The Strategy Design pattern, from the book Design patterns written by the Gang of Four, has the following statement in the Consequences section:
Strategies eliminate conditional statements. The ...
0
votes
0
answers
331
views
Simple spell checker using Levenshtein distance
I have to implement a simple spell checker. Basically I have to user input an incorrect sentence or a word, then a number N, and then N correct words each on new line. The program has to output "...
0
votes
1
answer
590
views
what will be the cyclomatic complexity of this c++ code
int x = 99;
int a = 4;
int parity;
while (x < 100)
{
if (a % 2 == 0)
{
parity = 0;
}
else
{
parity = 1;
}
switch (parity)
{
case 0:
cout &...
2
votes
1
answer
41
views
Understanding Cyclomatic complexity of a simple condition
I am trying to understand the cyclomatic complexity concept and came across in web that the cyclomatic complexity for below code (pseudo) is 3, but I thought, as there are 4 possible test scenarios, ...
1
vote
1
answer
4k
views
Cyclomatic Complexity in Intellij
I was working on an assignment today that basically asked us to write a Java program that checks if HTML syntax is valid in a text file. Pretty simple assignment, I did it very quickly, but in doing ...
1
vote
2
answers
58
views
Limiting a number without a conditional
Consider the following function:
def absolute_value(some_number):
if some_number < 0:
return -some_number
return some_number
and this one:
def absolute_value(some_number):
...
0
votes
2
answers
665
views
Reduce the cyclomatic complexity of a typescript method
Provided is the typescript function, where we need to reduce the cyclometric complexity. I am thinking off to provide the inverted if but that doesn't help much.
updateSort(s: Sort) {
if (s....
6
votes
0
answers
115
views
Why aren't switch expressions counted in cyclomatic complexity?
Let's say I have this method:
void DoStuff(int a)
{
int b;
switch (a)
{
case 1:
b = 5;
break;
case 2:
b = 100;
break;
...
0
votes
1
answer
600
views
Calculate cyclomatic complexity from file in different programming language via script
I am working on writing a script that outputs information about my written source code.
So far, I am analysing the code with Python scripts that I have written.
There is a Test.cs class which is used ...
4
votes
0
answers
1k
views
Should I use cyclomatic complexity in React?
I'm working on a React application using functional components. The lint configuration file has Cyclomatic Complexity enabled. That means that every component or custom hook that has too many logical ...