Skip to main content
The 2024 Developer Survey results are live! See the results

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
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 ...
SimicSlaw's user avatar
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 ...
Mikel Solaguren's user avatar
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 ...
kakadesachin's user avatar
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 ...
Dan's user avatar
  • 12.6k
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. ...
BSaleh's user avatar
  • 23
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 ...
Niek Beijloos's user avatar
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 "...
Raluca123's user avatar
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 &...
Ramneet Singh's user avatar
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, ...
Jay's user avatar
  • 21
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 ...
Ben Sailor's user avatar
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): ...
Tuğberk Özdemir's user avatar
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....
Mayank Gupta's user avatar
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; ...
Nigel's user avatar
  • 3,171
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 ...
41 72 6c's user avatar
  • 1,720
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 ...
Federico Bellucci's user avatar

15 30 50 per page
1
2 3 4 5
20