Function moveBasicBlock
has a Cognitive Complexity of 121 (exceeds 5 allowed). Consider refactoring. Open
function moveBasicBlock(method, bblocks, gotoLabel){
//console.log("Moving basic blocks "+bblocks.offset+"(len:"+bblocks.blk.length+") at instr goto_"+gotoLabel);
let bbs = [], flag=false, lastWasGoto=false, endbb=0, tmp=null;
// find cut point
if( method.instr != null && method.instr.length > 0){
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
File main.js
has 459 lines of code (exceeds 250 allowed). Consider refactoring. Open
const IFC = require("../../../src/InspectorFrontController.js");
var CONST = require("../../../src/CoreConst.js");
const Disassembler = require("../../../src/Disassembler.js");
var Controller = new IFC.FrontController();
Function findTargetBasicBlocks
has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring. Open
function findTargetBasicBlocks(method, gotoLabel){
//console.log("Searching block at :goto_"+gotoLabel);
let targetBBs = null, found=false, offset=0, duplicate=false;
if( method.instr != null && method.instr.length > 0){
for(let i=0; i<method.instr.length ; i++){
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function moveBasicBlock
has 72 lines of code (exceeds 25 allowed). Consider refactoring. Open
function moveBasicBlock(method, bblocks, gotoLabel){
//console.log("Moving basic blocks "+bblocks.offset+"(len:"+bblocks.blk.length+") at instr goto_"+gotoLabel);
let bbs = [], flag=false, lastWasGoto=false, endbb=0, tmp=null;
// find cut point
if( method.instr != null && method.instr.length > 0){
Function flatternGotoOf
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
function flatternGotoOf(method){
let blocksToMove = null;
let singleGoto = findSingleGoto(method);
let ret = false;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function findSingleGoto
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
function findSingleGoto(method){
let found = {}, singles = [];
// count GOTOs
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function nextSingleGoto
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
function nextSingleGoto(method){
let found = {}, singles = [];
// count GOTOs
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function gotoLocalXref
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
function gotoLocalXref(method,goto_name){
let xref = {
name: null,
ref: [],
ctr: 0
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function findTargetBasicBlocks
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
function findTargetBasicBlocks(method, gotoLabel){
//console.log("Searching block at :goto_"+gotoLabel);
let targetBBs = null, found=false, offset=0, duplicate=false;
if( method.instr != null && method.instr.length > 0){
for(let i=0; i<method.instr.length ; i++){
Function checkIfEligible
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
function checkIfEligible(method){
let notElgible = [
CONST.INSTR_TYPE.IF,
CONST.INSTR_TYPE.SWITCH,
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function renameStaticInterface
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
function renameStaticInterface(database, method, pContext){
if(!hasSingleCall(method)) return false;
if(method.args.length==0) return false;
Function flatternGotoOf
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
function flatternGotoOf(method){
let blocksToMove = null;
let singleGoto = findSingleGoto(method);
let ret = false;
Function renameStaticInterface
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
function renameStaticInterface(database, method, pContext){
if(!hasSingleCall(method)) return false;
if(method.args.length==0) return false;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid deeply nested control flow statements. Open
if(method.instr[i].hasInstr(CONST.INSTR_TYPE.RET))
duplicate = true;
Avoid deeply nested control flow statements. Open
if(found[instruction.right.name]===undefined)
found[instruction.right.name]=1;
else
found[instruction.right.name]+=1;
Avoid deeply nested control flow statements. Open
else if(lastWasGoto){
if(instruction.opcode.type !== CONST.INSTR_TYPE.NOP){
console.log("[ERROR] CFG changed !!!");
}
}
Avoid deeply nested control flow statements. Open
if(hasJump(method.instr[i].stack)){
if(DEBUG) console.log("block has jump POST :",gotoLabel,targetBBs[targetBBs.length-1].stack);
break;
}
Avoid deeply nested control flow statements. Open
if(instruction.right.name == gotoLabel){
//console.log(bblocks);
Avoid deeply nested control flow statements. Open
if(found[instruction.right.name]===undefined)
found[instruction.right.name]=1;
else
found[instruction.right.name]+=1;
Avoid deeply nested control flow statements. Open
if(DEBUG) console.log("block has jump :",method.instr[i].goto_name,gotoLabel,targetBBs);
Avoid deeply nested control flow statements. Open
if(j !== method.instr[i].stack.length-1){
console.log(method.signature(),"[:goto_"+goto_name,"] Not the last instruction")
}
Function renameDoubleStatic
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
function renameDoubleStatic(database, method, pContext){
if(!hasSingleCall(method)) return false;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this function. Open
return true;
Avoid too many return
statements within this function. Open
return false;
Avoid too many return
statements within this function. Open
return true;
Avoid too many return
statements within this function. Open
if(paramOnly === false) return false;
Identical blocks of code found in 2 locations. Consider refactoring. Open
args.map( pLocation => {
let instr = method.getInstr(pLocation.bb,pLocation.instr);
if(instr != null){
instr.left.map( vParam => {
if(vParam.t !== CONST.LEX.TOKEN.PARAM) paramOnly = false;
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 103.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
args.map( pLocation => {
let instr = method.getInstr(pLocation.bb,pLocation.instr);
if(instr != null){
instr.left.map( vParam => {
if(vParam.t !== CONST.LEX.TOKEN.PARAM) paramOnly = false;
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 103.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76