Method glob_helper
has a Cognitive Complexity of 177 (exceeds 5 allowed). Consider refactoring. Open
private static int glob_helper(Ruby runtime, String cwd,
byte[] path, int begin, int end, Encoding enc, int sub,
int flags, GlobFunc<GlobArgs> func, GlobArgs arg) {
int status = 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 Dir.java
has 745 lines of code (exceeds 250 allowed). Consider refactoring. Open
/***** BEGIN LICENSE BLOCK *****
* Version: EPL 2.0/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Eclipse Public
* License Version 2.0 (the "License"); you may not use this file
Method helper
has a Cognitive Complexity of 66 (exceeds 5 allowed). Consider refactoring. Open
int helper(byte[] pbytes, int pend, byte[] sbytes, int send, Encoding enc) {
int s = scur;
int p = pcur;
int ptmp = -1;
- 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
Method bracket
has a Cognitive Complexity of 64 (exceeds 5 allowed). Consider refactoring. Open
public int bracket(byte[] pbytes, int p, int pend, byte[] sbytes, int s, int send, Encoding enc) {
boolean not = false;
boolean ok = false;
int r;
int c1, c2;
- 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
Method braces
has a Cognitive Complexity of 48 (exceeds 5 allowed). Consider refactoring. Open
public static ArrayList<String> braces(String pattern, int flags, ArrayList<String> patterns) {
boolean escape = (flags & FNM_NOESCAPE) == 0;
int rbrace = -1;
int lbrace = -1;
- 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
Method fnmatch
has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring. Open
public static int fnmatch(
byte[] bytes, int pstart, int pend,
byte[] string, int sstart, int send, int flags, Encoding enc) {
// This method handles '**/' patterns and delegates to
- 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
Method push_braces
has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring. Open
private static int push_braces(Ruby runtime, String cwd, List<ByteList> result, GlobPattern pattern, boolean sort) {
pattern.reset();
int lbrace = pattern.indexOf((byte) '{'); // index of left-most brace
int rbrace = pattern.findClosingIndexOf(lbrace);// index of right-most brace
- 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
Method glob_helper
has 135 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static int glob_helper(Ruby runtime, String cwd,
byte[] path, int begin, int end, Encoding enc, int sub,
int flags, GlobFunc<GlobArgs> func, GlobArgs arg) {
int status = 0;
Method helper
has 86 lines of code (exceeds 25 allowed). Consider refactoring. Open
int helper(byte[] pbytes, int pend, byte[] sbytes, int send, Encoding enc) {
int s = scur;
int p = pcur;
int ptmp = -1;
Dir
has 28 methods (exceeds 20 allowed). Consider refactoring. Open
public class Dir {
public final static boolean DOSISH = Platform.IS_WINDOWS;
public final static boolean CASEFOLD_FILESYSTEM = DOSISH;
public final static int FNM_NOESCAPE = 0x01;
Method addToResultIfExists
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
private static int addToResultIfExists(Ruby runtime, String cwd, byte[] bytes, int begin, int end, Encoding enc, int flags, GlobFunc<GlobArgs> func, GlobArgs arg) {
final String fileName = new String(bytes, begin, end - begin, enc.getCharset());
// FIXME: Ultimately JRubyFile.createResource should do this but all 1.7.x is only selectively honoring raw
// paths and using system drive make it absolute. MRI does this on many methods we don't.
- 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
Method bracket
has 57 lines of code (exceeds 25 allowed). Consider refactoring. Open
public int bracket(byte[] pbytes, int p, int pend, byte[] sbytes, int s, int send, Encoding enc) {
boolean not = false;
boolean ok = false;
int r;
int c1, c2;
Method braces
has 56 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static ArrayList<String> braces(String pattern, int flags, ArrayList<String> patterns) {
boolean escape = (flags & FNM_NOESCAPE) == 0;
int rbrace = -1;
int lbrace = -1;
Consider simplifying this complex logical expression. Open
if (lbrace == -1 || rbrace == -1 ||
lbrace > 0 && pattern.bytes[lbrace-1] == '\\' && (lbrace <= 1 || pattern.bytes[lbrace-2] != '\\') ||
rbrace > 0 && pattern.bytes[rbrace-1] == '\\' && (rbrace <= 1 || pattern.bytes[rbrace-2] != '\\')) {
ByteList unescaped = new ByteList(pattern.bytes.length - 1);
unescaped.setEncoding(pattern.enc);
Method fnmatch
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static int fnmatch(
byte[] bytes, int pstart, int pend,
byte[] string, int sstart, int send, int flags, Encoding enc) {
// This method handles '**/' patterns and delegates to
Method push_braces
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static int push_braces(Ruby runtime, String cwd, List<ByteList> result, GlobPattern pattern, boolean sort) {
pattern.reset();
int lbrace = pattern.indexOf((byte) '{'); // index of left-most brace
int rbrace = pattern.findClosingIndexOf(lbrace);// index of right-most brace
Method has_magic
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
private static boolean has_magic(byte[] bytes, int begin, int end, int flags) {
boolean escape = (flags & FNM_NOESCAPE) == 0;
boolean nocase = (flags & FNM_CASEFOLD) != 0;
int open = 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
Method glob_helper
has 10 arguments (exceeds 4 allowed). Consider refactoring. Open
private static int glob_helper(Ruby runtime, String cwd,
byte[] path, int begin, int end, Encoding enc, int sub,
int flags, GlobFunc<GlobArgs> func, GlobArgs arg) {
Method addToResultIfExists
has 9 arguments (exceeds 4 allowed). Consider refactoring. Open
private static int addToResultIfExists(Ruby runtime, String cwd, byte[] bytes, int begin, int end, Encoding enc, int flags, GlobFunc<GlobArgs> func, GlobArgs arg) {
Method addToResultIfExists
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static int addToResultIfExists(Ruby runtime, String cwd, byte[] bytes, int begin, int end, Encoding enc, int flags, GlobFunc<GlobArgs> func, GlobArgs arg) {
final String fileName = new String(bytes, begin, end - begin, enc.getCharset());
// FIXME: Ultimately JRubyFile.createResource should do this but all 1.7.x is only selectively honoring raw
// paths and using system drive make it absolute. MRI does this on many methods we don't.
Method fnmatch
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
byte[] bytes, int pstart, int pend,
byte[] string, int sstart, int send, int flags, Encoding enc) {
Method glob_helper
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
private static int glob_helper(Ruby runtime, String cwd, ByteList path, int sub, int flags, GlobFunc<GlobArgs> func, GlobArgs arg) {
Method bracket
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
public int bracket(byte[] pbytes, int p, int pend, byte[] sbytes, int s, int send, Encoding enc) {
Method fnmatch
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
byte[] bytes, int pstart, int pend,
byte[] string, int sstart, int send, int flags) {
Avoid deeply nested control flow statements. Open
if(pos == rbrace) {
break;
}
Avoid deeply nested control flow statements. Open
if ( fnmatch(STAR, 0, 1, fileBytes, 0, fileBytes.length, flags) != 0) {
continue;
}
Method findClosingIndexOf
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public int findClosingIndexOf(int leftTokenIndex) {
if (leftTokenIndex == -1 || leftTokenIndex > end) return -1;
byte leftToken = bytes[leftTokenIndex];
byte rightToken;
- 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 ( status != 0 ) break finalize;
Avoid deeply nested control flow statements. Open
if (length == 1) {
if (recursive && (flags & FNM_DOTMATCH) == 0) continue;
if (skipdot) continue;
} else if (length == 2 && file.charAt(1) == '.') {
continue;
Avoid deeply nested control flow statements. Open
if ( status == 0 ) {
resource = JRubyFile.createResource(runtime, cwd, RubyString.byteListToString(link));
if ( resource.isDirectory() ) {
final int len = link.getRealSize();
buf.length(0);
Avoid deeply nested control flow statements. Open
if(Arrays.equals(magic, DOUBLE_STAR)) {
remainingPathStartIndex = nextStartIndex;
} else {
remainingPathStartIndex = nextStartIndex - 1;
}
Avoid deeply nested control flow statements. Open
if ( !resource.isSymLink() && resource.isDirectory() && !".".equals(file) && !"..".equals(file) ) {
final int len = buf.getRealSize();
buf.append(SLASH);
buf.append(DOUBLE_STAR);
buf.append(path, SLASH_INDEX, end - SLASH_INDEX);
Method push_globs
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
private static int push_globs(Ruby runtime, String cwd, List<ByteList> ary, ByteList pattern, int flags, boolean sort) {
Avoid deeply nested control flow statements. Open
if ( SLASH_INDEX == -1 ) {
status = func.call(buf.getUnsafeBytes(), 0, buf.getRealSize(), enc, arg);
if ( status != 0 ) break;
continue;
}
Method range
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public static int range(byte[] _pat, int pat, int pend, char test, int flags) {
Method call
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public int call(byte[] ptr, int p, int len, Encoding enc, GlobArgs args) {
Method call
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public int call(byte[] ptr, int p, int len, Encoding enc, List<ByteList> ary) {
Method call
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
int call(byte[] ptr, int p, int len, Encoding enc, T ary);
Method push_braces
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
private static int push_braces(Ruby runtime, String cwd, List<ByteList> result, GlobPattern pattern, boolean sort) {
Method helper
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
int helper(byte[] pbytes, int pend, byte[] sbytes, int send, Encoding enc) {
Method push_glob
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public static List<ByteList> push_glob(Ruby runtime, String cwd, ByteList globByteList, int flags, boolean sort) {
Method isSpecialFile
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private static boolean isSpecialFile(String name) {
int length = name.length();
if (length < 1 || length > 3 || name.charAt(0) != '.') return false;
if (length == 1) return true;
- 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 method. Open
return ok == not ? -1 : p + 1;
Avoid too many return
statements within this method. Open
return FNM_NOMATCH;
Avoid too many return
statements within this method. Open
if (t2 >= pend) return -1;
Avoid too many return
statements within this method. Open
return FNM_NOMATCH;
Avoid too many return
statements within this method. Open
return FNM_NOMATCH;
Avoid too many return
statements within this method. Open
return isEnd(pbytes, p, pend) ? 0 : FNM_NOMATCH;
Identical blocks of code found in 2 locations. Consider refactoring. Open
rbrace > 0 && pattern.bytes[rbrace-1] == '\\' && (rbrace <= 1 || pattern.bytes[rbrace-2] != '\\')) {
- 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 52.
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
lbrace > 0 && pattern.bytes[lbrace-1] == '\\' && (lbrace <= 1 || pattern.bytes[lbrace-2] != '\\') ||
- 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 52.
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