cyclomatic-complexity

How can the cyclomatic complexity be 27 in a method with 13 event handler subscriptions?

ぐ巨炮叔叔 提交于 2019-12-04 04:49:36
We have this code, sortof: private void InitializeEvents() { this.Event1 += (s,e) => { }; this.Event2 += (s,e) => { }; this.Event3 += (s,e) => { }; this.Event4 += (s,e) => { }; this.Event5 += (s,e) => { }; this.Event6 += (s,e) => { }; this.Event7 += (s,e) => { }; this.Event8 += (s,e) => { }; this.Event9 += (s,e) => { }; this.Event10 += (s,e) => { }; this.Event11 += (s,e) => { }; this.Event12 += (s,e) => { }; this.Event13 += (s,e) => { }; } Code analysis in VS10 Ultimate says "cyclomatic complexity of 27". Removing one of the lines makes the cyclomatic complexity 25. There's no branching going

How to improve Cyclomatic Complexity?

試著忘記壹切 提交于 2019-12-03 11:04:07
Cyclomatic Complexity will be high for methods with a high number of decision statements including if/while/for statements. So how do we improve on it? I am handling a big project where I am supposed to reduced the CC for methods that have CC > 10. And there are many methods with this problem. Below I will list down some eg of code patterns (not the actual code) with the problems I have encountered. Is it possible that they can be simplified? Example of cases resulting in many decision statements: Case 1) if(objectA != null) //objectA is a pass in as a parameter { objectB = doThisMethod(); if

Cyclomatic Complexity in piece of code with multiple exit points

走远了吗. 提交于 2019-12-03 08:01:08
I have this method that validates a password: /** * Checks if the given password is valid. * * @param password The password to validate. * @return {@code true} if the password is valid, {@code false} otherwise. */ public static boolean validatePassword(String password) { int len = password.length(); if (len < 8 || len > 20) return false; boolean hasLetters = false; boolean hasDigits = false; for (int i=0; i<len; i++) { if (!Character.isLetterOrDigit(password.charAt(i))) return false; hasDigits = hasDigits || Character.isDigit(password.charAt(i)); hasLetters = hasLetters || Character.isLetter

How to reduce cyclomatic complexity?

拥有回忆 提交于 2019-12-03 05:39:54
问题 I'm working on a class which sends a RequestDTO to a Web Service. I need to validate the request before it is sent. The request can be sent from 3 different places and there are different validation rules for each "requesttype", e.g. request1 must have name and phonenumber, request2 must have address, etc) I have a DTO which contains a long list of fields (name, address, city, phonenumber, etc.) and it is the same DTO sent no matter which type of request it is. I have created 3 different

Calculate Cyclomatic Complexity for Javascript [closed]

你。 提交于 2019-12-03 01:39:57
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . Are there any tools available for calculating Cyclomatic Complexity in Javascript? I've found it a very helpful metric in the past while working on server side code, and would like to be able to use it for the client side Javascript I write. 回答1: I helped write a tool to perform software complexity analysis on

Measuring the complexity of SQL statements

亡梦爱人 提交于 2019-12-02 16:17:49
The complexity of methods in most programming languages can be measured in cyclomatic complexity with static source code analyzers. Is there a similar metric for measuring the complexity of a SQL query? It is simple enough to measure the time it takes a query to return, but what if I just want to be able to quantify how complicated a query is? [Edit/Note] While getting the execution plan is useful, that is not necessarily what I am trying to identify in this case. I am not looking for how difficult it is for the server to execute the query, I am looking for a metric that identifies how

Calculate Cyclomatic Complexity for Javascript [closed]

大城市里の小女人 提交于 2019-12-02 15:08:28
Are there any tools available for calculating Cyclomatic Complexity in Javascript? I've found it a very helpful metric in the past while working on server side code, and would like to be able to use it for the client side Javascript I write. I helped write a tool to perform software complexity analysis on JavaScript projects: complexity-report It reports a bunch of different complexity metrics: lines of code, number of parameters, cyclomatic complexity, cyclomatic density, Halstead complexity measures, the maintainability index, first-order density, change cost and core size. It is released

Code Metrics Calculation in Visual Studio

主宰稳场 提交于 2019-12-02 14:52:10
What is the prefered score range for the code metrics calculation for the following Maintainability Index Cyclomatic Complexity Depth of Inheritance class Coupling The theoretically optimal values are: Maintainability index: 100. Higher values indicate better maintainability. Cyclomatic complexity: 1. The number of different paths that code can take. Depth of inheritance: 1. The number of class definitions above this one in the inheritance tree, not including interfaces. Class coupling: 0. Number of other entities this entity is dependent on. There are no hard and fast "good" ranges, though it

Clarifying the manual count of Cyclomatic Complexity

痴心易碎 提交于 2019-12-02 00:29:29
Let's assume that we have a code like this: switch(y) { case 1: case 2: case 3: function(); break; case 4: case 5: case 6: function_2(); break; } Can we get the CC value as 6+1 here? Why a value of 1 is added? If the CC value is considered as 7, is that the number of independent paths? What if a fall through scenario is considered above? As only possible two unique paths are there, 2 +1 =3 Which of the above are correct or are the both of them correct? As we know, CC = P+1. Here, P = number of predicate nodes (conditions) = 2 Number of conditions will be 2 because: Case branch can cover

Deriving Cyclomatic Complexity in .NET

ぃ、小莉子 提交于 2019-12-01 06:03:53
I know that I can access the cyclomatic complexity to my code in Visual Studio 2008 Team Explorer by right clicking and selecting "Calculate Code Metrics". I would like to expose this data for a web application to display it. Does anybody know of any way of accessing this data through an API? Thanks for your help! Paco I use NDepend for stuff like that. You can create CQL queries in NDepend and execute them. Example: SELECT METHODS WHERE CC > 8 returns the methods with a cyclomatic complexity greater than 8. nulltoken As described in this answer , one can leverage the API of the Gendarme open