Showing 33 of 33 total issues
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (apiCall.params && apiCall.request) {
apiCall.request.params = apiCall.params;
delete apiCall.params;
}
- 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 47.
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
Function end
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
end: function(suite, test, apiCall, err, result) {
var method = apiCall.request['method'] || "GET";
if (apiCall.it || apiCall.description) output(" "); // indentation
output(method + " " + apiCall.request.url);
var status = err ? "FAILURE!" : "OK!";
- 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 nestedValue
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
var nestedValue = (function() {
var assertValidArgs = function(hash, nestedKey) {
if (hash == null || typeof hash !== 'object') {
throw new UtilError('nested_value_invalid_hash', 'Expected object as hash argument but got ' + hash + " nestedKey=" + nestedKey);
}
- 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 expandPaths
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
var expandPaths = function(paths, extensions, topLevel) {
return util.compact(util.flatten(util.map(util.array(paths), function(path) {
if (fs.existsSync(path) && fs.lstatSync(path).isDirectory()) {
var subPaths = util.compact(util.map(fs.readdirSync(path), function(subPath) {
return join(path, subPath);
- 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 start
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
start: function(suite, test, apiCall) {
if (apiCall.pending) {
stats.pending_api_calls++;
} else {
stats.api_calls++;
- 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 value1.toString() === value2.toString();
Avoid too many return
statements within this function. Open
return false;
Avoid too many return
statements within this function. Open
return false;
Function prepareStringify
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
var prepareStringify = function(object) {
if (isIterable(object)) {
Object.keys(object).forEach(function(key) {
var value = object[key];
if (_.isRegExp(value)) {
- 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 assertValid
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
var assertValid = function(positive, result) {
if (positive) {
return result.error_messages ? result.error_messages.length === 0 : result;
} else {
return result.error_messages ? result.error_messages.length > 0 : !result;
- 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 normalizeRequest
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
var normalizeRequest = function(apiCall) {
var request = apiCall.request;
if (request) {
if (request.url == null && request.path && request.base_url) {
request.url = request.base_url + request.path;
- 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 end
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
end: function(suite, test, apiCall) {
var request = apiCall.request,
url = request.url,
args = [
'-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 applyPattern
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
var applyPattern = function(value, response) {
if (response == null) return undefined;
var matchValue = (typeof response === 'object' ? JSON.stringify(response) : response);
var match = new RegExp(value).exec(matchValue);
if (match !== null) {
- 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"