Questions tagged [cyclomatic-complexity]
Cyclomatic Complexity is a metric of the complexity of a program or a section of a program.
61 questions
2
votes
1
answer
93
views
Semi-generic data loading utility class
The following implements a relatively generic and modular data loading utility. It loads images from a local storage given a lookup table. The data loader is parametrized via dependency injection to ...
1
vote
1
answer
538
views
Comparison of lists of intervals
From the following script, the "similarity" function should be callable to compare two sets of lists and return a certain similarity score. The elements of the lists represent intervals, so [...
1
vote
2
answers
175
views
Parse string using character value for Unicode characters
I added the getCValue method to reduce the cyclomatic complexity, but the cyclomatic complexity still persists. How can I reduce it? Can I change this code using ...
3
votes
2
answers
130
views
C# Tool to Generate MS Word Document Mailbox List From MS Excel
There is now a Follow up question to this question.
Abstract
The VBA solution didn't work on the clients computer because Office 2010 Starter Edition doesn't support VBA. I decided to try a C# ...
3
votes
2
answers
78
views
Simplify 2D point angle comparator
I have a comparison function for comparing two points in 2 (or more) dimensions based on the angle of each point in standard polar coordinates. In other words, a point ...
0
votes
2
answers
316
views
Optimizing methods with multiple if checks on getter values
I have a method where I fetch user input, check if certain values exist, and based on that build my own custom input object that I would use to search in a database. The code for the search method is ...
5
votes
1
answer
93
views
Hand Coded State Driven Lexical Analyzer in C With Unit Test Part C
This review is presented in 3 questions due to the amount of code:
Part A contains the Lexical Analyzer and the main portion of the unit test code.
Part B contains the lower level unit tests called ...
4
votes
1
answer
64
views
Hand Coded State Driven Lexical Analyzer in C With Unit Test Part B
This review is presented in 3 questions due to the amount of code:
Part A contains the Lexical Analyzer and the main portion of the unit test code.
Part B (this question) contains the lower level ...
9
votes
2
answers
298
views
Hand Coded State Driven Lexical Analyzer in C With Unit Test Part A
This code review is presented in 3 questions due to the amount of code:
Part A (this question) contains the Lexical Analyzer and the main portion of the unit test code.
Part B contains the lower ...
1
vote
2
answers
98
views
Parser for file made up of sections
I'm parsing a file made up of various sections. I have a current_section variable that tracks which portion of the file I'm currently processing and the following <...
0
votes
1
answer
191
views
Case of Cyclomatic Complexity
I'm trying to recreate the method inject (Works like Reduce) from ruby Enumerable Module.
Using Rubocop (A Linter) I got the error:
...
4
votes
1
answer
156
views
Method that filters a list parameters based on different fields
I have this code which is a callback for Filter in WPF ICollectionView. When I run code analysis, the cyclometic complexity is reported to be 11. I consider this ...
1
vote
2
answers
68
views
Files.walkTree is causing Assignment Branch Condition too high [closed]
My code is working correctly, but is resulting in a "Assignment branch condition too high" warning with a score of 12.08 on CodeBeat.
Codebeat is an automated code review utility that helps ...
6
votes
2
answers
21k
views
handle null in Comparator class
I have a class LoanAccount that contains an attributes creationDate and loanAmount.
I ...
14
votes
2
answers
734
views
Get the encrypted payload from an unencrypted wrapper PDF document
This is code, written by our dev team, and SonarQube tells me that the Cognitive Complexity is too high: 21, and the current (default, out of the box) metric limit is 15. I've had a go at reducing the ...
1
vote
1
answer
89
views
Automatically select the table rows between two selected rows
The code is to check the rows in a table. If in a table two non consecutive rows are checked then all the in between rows should be selected by itself. Also, after selecting two rows, on selection of ...
1
vote
1
answer
73
views
Work command handler for an economy system
I have been working on this code, which is the part of an economy system that handles the work command. This lets the user pick a role and if they have enough level then they will get it by updating a ...
3
votes
2
answers
338
views
Descending selection sort in JavaScript
I wrote a simple sort algorithm in JavaScript, but code climate is complaining its complexity being too high (currently sitting on 6 instead of 5, which is code climate wants).
I personally cannot ...
3
votes
1
answer
70
views
JavaScript function to categorize data by their "styles" attribute, and store the key-"unicode" pair
I have a JavaScript function to categorize data by their "styles" attribute, and store the key-"unicode" pair.
Here's my current code:
...
4
votes
1
answer
257
views
Culling strings from a list that are substrings of other list elements
I'm bothered by my answer to this SO question.
I'm pretty sure it's more efficient than the sort-and-cull implementations, but I'm having trouble expressing that in a way that I trust.
Also, it's ...
8
votes
5
answers
623
views
Checks user level and limit the data before saving it to mongoDB
I have a function that checks user level and limits the data before saving it to mongoDB database (pre 'save' middleware for mongoose).
It have been getting complexity warnings and tried to rewrite it,...
3
votes
2
answers
166
views
Keep ABC size down for conditional string concatenation in Ruby
This method takes a comment object and displays it correctly depending on what columns are available. EVENT_TEXT and REASON_TEXT ...
4
votes
3
answers
600
views
Poker Game: Refactor method to evaluate poker hands
Preface: I've perused the other related questions before creating this one but I believe that those solutions weren't applicable to my situation. I'll concede that its possible that I may not have ...
0
votes
1
answer
140
views
Php: how to lower complexity of method [closed]
I have this method rated B on Scrutinizer (direct link: https://scrutinizer-ci.com/g/sineverba/domotic-panel/inspections/76996c9f-543f-43b4-9475-c64fe810a278/code-structure/operation/App%5CHttp%...
2
votes
2
answers
72
views
Express.js handler to update user fields
I have an express handler which i thought was pretty simple, but CodeClimate flagged this method as having a Cognitive complexity of 6 (5 is the max by default without flagging something)
Curious how ...
5
votes
1
answer
13k
views
Convert to UTF-8 all files in a directory
1. Summary
I can't find, how I can to refactor multiple with open for one file.
2. Expected behavior of program
Program detect encoding for each file in the ...
7
votes
0
answers
91
views
Set an image sprite depending on the lowest common number in a set [closed]
In my game you can earn either a bronze, silver or gold medal. There is 4 difficulties which you can earn a medal on.
I want to display a medal depending on the lowest common medal earnt if that ...
5
votes
4
answers
71
views
Calculating total size of player data
I am writing a function to calculate the total size of a "player appearance".
There are various "item slots" the player has, and if they are empty then 1 byte will be sent, otherwise there will be 2.
...
2
votes
1
answer
1k
views
Group Anagrams Together approach in Java
Given an array of words, print the count of all anagrams together in
sorted order (increasing order of counts). For example, if the given
array is {“cat”, “dog”, “tac”, “god”, “act”}, then grouped ...
2
votes
1
answer
128
views
Convenience function for writing files in CSV, JSON, etc
The McCabe code complexity of the following function is 19 as found by pytest --mccabe test.py (from my toy-project mpu). While ...
4
votes
2
answers
133
views
Marking projects as done when all tasks' progress are 100%
We have project.task model, where each task has many lines and each line has progress field indicating how much work has been done and how much still remaining (...
2
votes
2
answers
301
views
Masking user input passwords
I have a method that accepts user input. Additionally, it masks passwords then the input is a password. It also bypasses the prompt of if an env variable supplies the needed input.
Apparently, my ...
3
votes
2
answers
1k
views
Most popular element with count in Array with Java
Here is the input array of int values
Example: { 5, 4, 6, 5, 1, 0, 7, 7, 3, 5 }
Find the most repeated element with its count, example output; ...
0
votes
2
answers
136
views
Verifying that all fields of a unit has been suitably filled in
I have unit class which have some properties, and I have acceptancePolicy table which contain values. If values (from one row) are true method should return true. The method is below. How can I ...
3
votes
2
answers
3k
views
Parsing command line arguments in Go
I've written a reimplementation of the redis-benchmark in Go and part of that is parsing options from the command line. I evaluated several libraries but nothing I found seem to do what I had in mind. ...
5
votes
1
answer
2k
views
DNS Zone file parser
I've coded this FileDNSParser class. It parses a BIND (RFC 1033) zone file and gets its resource records into an array.
Scrutizer CI says it too complex, and I'm sure there is too much nested ifs and ...
3
votes
3
answers
360
views
Apache POI and cyclomatic complexity of code
I have an Excel file, which I am reading using Apache POI APIs; which gives me control over cells/columns in my Excel.
I have around 17 columns in my Excel and these are with different datatypes. I ...
2
votes
1
answer
366
views
Function to determine the appropriate dimensions for a close button
How can I reduce the cyclomatic complexity of this CloseButtonDimensions function?
...
5
votes
1
answer
350
views
Collision detection method
I think everyone has some code they are embarrassed and not proud of and today I have decided to show mine. I'm not sure how to go about making this more efficient. At the time I was just happy it did ...
4
votes
3
answers
118
views
Check for Scrabble double letter bonus
This function checks if the cell of a Scrabble board is a double letter bonus. It has a 23 cyclomatic complexity, which is higher than the threshold of 20. I don't know how to do it another way, I ...
7
votes
1
answer
223
views
Python script to execute a Bash script and send a notification
I've written a Python script that given a few arguments executes a build process bash script.
...
3
votes
2
answers
110
views
Bubble sort code
I tried avoiding nested loops and usage of too many variables. This is up for review and comments.
...
2
votes
1
answer
283
views
play_card() method in an Exploding Kittens card game
I wrote a library for card games. To demonstrate how it can be used, I also wrote an Exploding Kittens card game as an example.
I'm using CodeClimate to determine cyclomatic complexity. This method ...
4
votes
1
answer
99
views
Finding the difference between postal addresses
I have to compose an email where I have to list a list of difference between old and new value of a list of addresses. Only a subset of properties have to be listed, so the first thing that pops into ...
4
votes
1
answer
62
views
Preview method for multiple types of panels
Using Rubocop, pretty much any case statement is caught by the Cyclomatic Complexity cop, often the Assignment Branch Condition and method length cops as well. To get around this, I've been ...
2
votes
3
answers
82
views
Factory to construct a FineTime out of many kinds of objects
Any suggestions to help refactor this method? I thought maybe some kind of factory to allocate the right type?
...
1
vote
1
answer
58
views
Establishing parameters for a sales report, with default boolean and date values
The idea is that I am getting the params from a GET request in the form of a Hash (symbol→str) and I want to transform them into dates and booleans. For that reason,...
3
votes
1
answer
76
views
Adding genres and themes from work
Codacy is telling me this method has a complexity of 13. I need some tips on how to reduce it, more specifically inside the forEach loop.
I've already changed it ...
2
votes
3
answers
131
views
File parsing and data management - follow-up
This is part of a two-part post (Part 1).
Here, I have two recent projects that parse a file. The first uses a loop that's kind of hard to follow, and the second uses "modes" to decide what to do.
...
3
votes
1
answer
477
views
File parsing and data management
This is part of a two-part post (Part 2).
Here, I have two recent projects that parse a file. The first uses a loop that's kind of hard to follow, and the second uses "modes" to decide what to do.
...