cyclomatic-complexity

reduce complexity of if elseif conditions

感情迁移 提交于 2021-01-05 07:09:47
问题 I have one function which is having if elseif conditions and the cyclomatic complexity is approaching 5. How do I reduce it? function testFunc() { var step = getModel('step'); if(step === 1) { this.resetTask(); //calling some function this.updateStep(0); return true; } else if(step === 2) { this.initTask; //some other function return true; } else if(step === 3) { this.name === 'add' ? this.add() : this.edit(); return true; } return false; } tried replacing with switch case but it didn't help.

reduce complexity of if elseif conditions

我怕爱的太早我们不能终老 提交于 2021-01-05 07:07:06
问题 I have one function which is having if elseif conditions and the cyclomatic complexity is approaching 5. How do I reduce it? function testFunc() { var step = getModel('step'); if(step === 1) { this.resetTask(); //calling some function this.updateStep(0); return true; } else if(step === 2) { this.initTask; //some other function return true; } else if(step === 3) { this.name === 'add' ? this.add() : this.edit(); return true; } return false; } tried replacing with switch case but it didn't help.

What would happen if a control flow graph consists of multiple start and/or stop nodes when calculating Cyclomatic Complexity

守給你的承諾、 提交于 2020-03-26 04:03:23
问题 I want to know how will it affect to the Cyclomatic Complexity when having multiple start or stop nodes in a control flow diagram.If you could explain the relationship between Cyclomatic Complexity and Start/Stop nodes it will be a great help. 回答1: • A control flow graph can consist of many starts and stops. But according to McCabe's theory, if it is consist of multiple starts and stops it doesn't satisfy the formula. 来源: https://stackoverflow.com/questions/60485378/what-would-happen-if-a

What would happen if a control flow graph consists of multiple start and/or stop nodes when calculating Cyclomatic Complexity

允我心安 提交于 2020-03-26 04:02:57
问题 I want to know how will it affect to the Cyclomatic Complexity when having multiple start or stop nodes in a control flow diagram.If you could explain the relationship between Cyclomatic Complexity and Start/Stop nodes it will be a great help. 回答1: • A control flow graph can consist of many starts and stops. But according to McCabe's theory, if it is consist of multiple starts and stops it doesn't satisfy the formula. 来源: https://stackoverflow.com/questions/60485378/what-would-happen-if-a

Reduce Cyclomatic Complexity of Switch Statement - Sonar

妖精的绣舞 提交于 2020-01-30 04:38:27
问题 I want to reduce cyclomatic complexity of my switch case my code is : public String getCalenderName() { switch (type) { case COUNTRY: return country == null ? name : country.getName() + HOLIDAY_CALENDAR; case CCP: return ccp == null ? name : ccp.getName() + " CCP" + HOLIDAY_CALENDAR; case EXCHANGE: return exchange == null ? name : exchange.getName() + HOLIDAY_CALENDAR; case TENANT: return tenant == null ? name : tenant.getName() + HOLIDAY_CALENDAR; default: return name; } } This code blocks

Reduce Cyclomatic Complexity of Switch Statement - Sonar

馋奶兔 提交于 2020-01-30 04:38:11
问题 I want to reduce cyclomatic complexity of my switch case my code is : public String getCalenderName() { switch (type) { case COUNTRY: return country == null ? name : country.getName() + HOLIDAY_CALENDAR; case CCP: return ccp == null ? name : ccp.getName() + " CCP" + HOLIDAY_CALENDAR; case EXCHANGE: return exchange == null ? name : exchange.getName() + HOLIDAY_CALENDAR; case TENANT: return tenant == null ? name : tenant.getName() + HOLIDAY_CALENDAR; default: return name; } } This code blocks

Sonar -LOC & Cyclomatic complexity

送分小仙女□ 提交于 2020-01-15 09:28:46
问题 How does Sonar calculates software metrics particularly LOC and cyclomatic complexity? Does it uses any particular tools? IF yes, please also give the names. 回答1: For each supported language, a "squid" plugin is used to parse the source code and determine some base metrics such as LOC and complexity. How the complexity is calculated varies based on the plugin. For example, here's the source code files for the JavaScript plugin: https://github.com/SonarCommunity/sonar-javascript/tree/master

java switch cyclomatic complexity vs performance

痴心易碎 提交于 2020-01-15 02:40:50
问题 I have a case here where the switch statement contains about 40 cases of each returning a different configured object based on input. This method is shown as having too high cyclomatic complexity in the metrics and usually I would change this into a map of handler objects. But this switch sits in a piece of code where performance is all-important so I came up with the question of how a HashMap lookup and handler call compares to a switch block execution performance-wise. Anyone compared that