Showing 107 of 107 total issues
Method clear?
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def clear?(answer, question)
# rubocop:disable LineLength
return true if question.is_a?(Questionnaires::Entities::Questions::SelectQuestion) && answer == question.extra_data[:placeholder].to_s
return true if question.is_a?(Questionnaires::Entities::Questions::StringQuestion) && answer == ""
return true if question.is_a?(Questionnaires::Entities::Questions::TextQuestion) && answer == ""
- 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(fieldsEmpty > 0 && fieldsEmpty < inputs.length) {
throw "invalidDate";
}
Avoid deeply nested control flow statements. Open
if(result == null || result[0] != value){
pushFailVal(validation.type);
}
Avoid deeply nested control flow statements. Open
if(count.visible > 0 && count.answered > validation.value){
pushFailVal(validation.type);
}
Method pdf
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def pdf
if defined?(Appsignal) && on_ios_safari?
session[:has_downloaded_pdf_for] = @answer.id
Appsignal.increment_counter("ios_safari_downloaded_pdf", 1)
end
- 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 check_aborted
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def check_aborted
if (params[:abort] && @questionnaire.abortable) ||
(params[:save_anyway] && (@display_mode == "bulk" || @display_mode == "single_page")) ||
(params[:previous_questionnaire])
params[:answer] ||= HashWithIndifferentAccess.new
- 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 (inputs.length == 3 && (values[0] != "" || values[1] != "" || values[2] != "")) {
value = values.join("-");
} else if (inputs.length == 1){
value = values[0];
}
Avoid deeply nested control flow statements. Open
if(!isNumber){
pushFailVal(validation.type);
}
Avoid deeply nested control flow statements. Open
if(count.visible > 0 && count.answered < validation.value){
pushFailVal(validation.type);
}
Avoid deeply nested control flow statements. Open
if (checkboxes.length < validation.minimum_checked_value) {
pushFailVal(validation.type);
}
Avoid deeply nested control flow statements. Open
if ($(inputs[0]).attr('class') === 'date') {
try {
if(allDateFieldsFilledIn(inputs)) {
var enteredDate = parsePartialDate(inputs);
var maximumDate = new Date(validation.value)
Avoid deeply nested control flow statements. Open
if(result === null || result[0] != value){
pushFailVal(validation.type);
}
Avoid deeply nested control flow statements. Open
if (!is_answered(inputs)) {
pushFailVal(validation.type);
}
Avoid deeply nested control flow statements. Open
if(value === undefined || value == ""){
continue;
}
Similar blocks of code found in 2 locations. Consider refactoring. Open
def validate_minimum(question, validation, value)
# We have decided not to allow bypassing this validation when
# aborted, since whatever is using this data further on is likely not
# built to take into account values outside the intended range. (e.g.
# BMI calculation)
- 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 39.
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
Similar blocks of code found in 2 locations. Consider refactoring. Open
def validate_maximum(question, validation, value)
# We have decided not to allow bypassing this validation when
# aborted, since whatever is using this data further on is likely not
# built to take into account values outside the intended range. (e.g.
# BMI calculation)
- 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 39.
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
Similar blocks of code found in 2 locations. Consider refactoring. Open
} else {
lastInput = panelInputs.filter(':eq('+index+'), :lt(' + index + ')').not(':hidden, :disabled').last();
}
- 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 49.
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
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (forward) {
lastInput = panelInputs.filter(':eq('+index+'), :gt(' + index + ')').not(':hidden, :disabled').first();
} else {
- 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 49.
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
Consider simplifying this complex logical expression. Open
if (params[:abort] && @questionnaire.abortable) ||
(params[:save_anyway] && (@display_mode == "bulk" || @display_mode == "single_page")) ||
(params[:previous_questionnaire])
params[:answer] ||= HashWithIndifferentAccess.new
params[:answer][:aborted] = true
Function setAllCheckboxes
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function setAllCheckboxes(checked, allKey, nothingKey, question, checkValue){