Questions tagged [cyclomatic-complexity]

Cyclomatic Complexity is a metric of the complexity of a program or a section of a program.

Filter by
Sorted by
Tagged with
3
votes
2answers
80 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
1answer
50 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: ...
2
votes
1answer
42 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 ...
0
votes
0answers
20 views

Complexity of a service method to fetch search results from an API

I tried the plug in CodeMetrics for Visual Studio Code along with some of my current Angular projects, and I was a little suprised about the outcome. I have a ...
6
votes
5answers
567 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,...
2
votes
2answers
59 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 ...
0
votes
1answer
60 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
2answers
31 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 ...
4
votes
1answer
3k 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 ...
5
votes
4answers
58 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
1answer
342 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
1answer
94 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
2answers
113 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
2answers
140 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
2answers
858 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; ...
-1
votes
2answers
122 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
2answers
2k 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
1answer
917 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
3answers
307 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
1answer
347 views

Function to determine the appropriate dimensions for a close button

How can I reduce the cyclomatic complexity of this CloseButtonDimensions function? ...
4
votes
3answers
100 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
1answer
160 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
2answers
95 views

Bubble sort code

I tried avoiding nested loops and usage of too many variables. This is up for review and comments. ...
2
votes
1answer
251 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
1answer
85 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
1answer
57 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
3answers
78 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
1answer
51 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
1answer
72 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
3answers
116 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
1answer
329 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. ...
1
vote
2answers
124 views

Reducing code complexity for UsergridClient constructor

I'm initializing a class in JavaScript with a bunch of complex property checks. Codacy is showing that this is bad design and recommends reducing cyclomatic complexity. I'm at a loss for how to ...
3
votes
1answer
183 views

Calculating solutions for the game “24”

I was bored this evening and decided to create a program which calculates all the solutions for a given scenario of the game "24". The goal of this game is that you try to be the first one to find ...
3
votes
3answers
30k views

Check whether a date is a valid future date

I'm looking to increase the conciseness of this code. I realize that I can use Joda (or Java 8's new date API), but if I were to keep this to just Java 7, any suggestions? (I care less about ...
1
vote
1answer
135 views

Class to perform astronomical calculations

I would like to reduce the complexity of this calculate method as it is too long in my opinion. There is already a number of helper methods exist which are called throughout the method. I can't really ...
2
votes
2answers
2k views

split string into container on char; efficiently?

Here is my single parse code for splitting a std::string on a char into a ...
3
votes
2answers
178 views

Readability and cyclomatic complexity of database transaction code

I consider these two options exactly the same. I prefer the first one but I'm not sure if it's better than the second option in terms of cyclomatic complexity or readability. Assuming that this is ...
2
votes
1answer
469 views

Converting an input audio file to a monophonic FLAC file

I have the following method which basically converts an input audio file to a monophonic FLAC file. Now I am getting Member has cyclomatic complexity of 21 (105%) message in Visual Studio, while I've ...
2
votes
3answers
2k views

Validating the presence of properties in a document

How can I reduce cyclomatic complexity of validation and refactor it better way? ...
1
vote
2answers
160 views

Reducing cyclomatic complexity in a simple string concatenation

I have written the following function that takes an address object and builds a string using the object properties. It will later be used to display a tooltip <...
3
votes
2answers
612 views

Ruby function to fetch, filter, and generate data

I'm currently writing a script and I decided to run cane over it to look for some issues, and the following method was highlighted. I've done my best to cut it back, and at this point I'm inclined to ...
6
votes
4answers
578 views

State machine for handling Telnet sequences for an FTP server

I've asked Code Climate to generate metrics for the ftpd Ruby gem. It correctly identified the God class; I know what to do about that. But one of the smaller classes has me stumped. This is telnet....