Showing 296 of 296 total issues
Similar blocks of code found in 2 locations. Consider refactoring. Open
def self.should_render_as_form_ui(column_name, form_ui)
before_block = lambda do
@rendered_columns = []
@controller.view_context_class.any_instance.expects(:"active_scaffold_input_#{form_ui}").at_least_once.with do |column, _|
@rendered_columns << column.name
- 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 51.
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
Method do_create
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def do_create(options = {})
attributes = options[:attributes] || params[:record]
active_scaffold_config.model.transaction do
@record = new_model
# before assign params, to set foreign_type of constraints in polymorphic association with multiple id
- 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 active_scaffold_record_select
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def active_scaffold_record_select(record, column, options, value, multiple, ui_options: column.options)
unless column.association
raise ArgumentError, "record_select can only work against associations (and #{column.name} is not). " \
'A common mistake is to specify the foreign key field (like :user_id), instead of the association (:user).'
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 add_to_importmap
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def add_to_importmap
original_js = File.binread(IMPORTMAP)
if original_js.match?(/^pin +['"]active_scaffold['"](?=,|$)/)
say_status('skipped', "append active_scaffold to #{IMPORTMAP}", :yellow)
else
- 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 in_subform?
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def in_subform?(column, parent_record, parent_column)
return true unless column.association
if column.association.reverse.nil?
# Polymorphic associations can't appear because they *might* be the reverse association
- 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 []
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def [](val)
links = []
@set.each do |item|
next if item == :separator
- 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 update_record_from_params
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def update_record_from_params(parent_record, columns, attributes, avoid_changes = false)
crud_type = parent_record.new_record? ? :create : :update
return parent_record unless parent_record.authorized_for?(crud_type: crud_type)
multi_parameter_attrs = multi_parameter_attributes(attributes)
- 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 add_link
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def add_link(attribute, options = {})
column = @core.columns[attribute.to_sym]
raise ArgumentError, "unknown column #{attribute}" if column.nil?
raise ArgumentError, "column #{attribute} is not an association" if column.association.nil?
- 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 columns_from_constraint
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def columns_from_constraint(column_name, value)
return if params_hash?(value)
if value.is_a?(Array)
column = active_scaffold_config.columns[column_name]
- 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 add_query_string_to_cached_url
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def add_query_string_to_cached_url(link, url)
query_string, non_nested_query_string = query_string_for_action_links(link)
nested_params = !link.nested_link? && non_nested_query_string
if query_string || nested_params
url << (url.include?('?') ? '&' : '?')
- 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 setup_defaults_for_column
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def setup_defaults_for_column
if active_record_class.respond_to?(:defined_enums) && active_record_class.defined_enums[name.to_s]
@form_ui = :select
@options = {options: active_record_class.send(name.to_s.pluralize).keys.map(&:to_sym)}
elsif column_number?
- 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 handleSaveEditor
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
handleSaveEditor: function(anEvent) {
if (false === this.triggerDelegateCall('shouldCloseEditInPlace', true, anEvent))
return;
var editor = this.dom.find('[name]:input:not(:button,[name=""])').not('input:checkbox:not(:checked)').not('input:radio:not(:checked)');
Method add_to_importmap
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def add_to_importmap
original_js = File.binread(IMPORTMAP)
if original_js.match?(/^pin +['"]active_scaffold['"](?=,|$)/)
say_status('skipped', "append active_scaffold to #{IMPORTMAP}", :yellow)
else
Method condition_for_search_ui
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def condition_for_search_ui(column, value, like_pattern, search_ui)
case search_ui
when :boolean, :checkbox
if value == 'null'
condition_for_null_type(column, value)
Method display_action_links
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def display_action_links(action_links, record, options, &block)
options[:level_0_tag] ||= nil
options[:options_level_0_tag] ||= nil
options[:level] ||= 0
options[:first_action] = true
Method active_scaffold_new_record_subform
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def active_scaffold_new_record_subform(column, record, html_options, ui_options: column.options, new_record_attributes: nil, locals: {}, skip_link: false)
klass =
if column.association.polymorphic? && column.association.belongs_to?
type = record.send(column.association.foreign_type)
column.association.klass(record) if type.present? && (ui_options[:add_new] == true || type.in?(ui_options[:add_new]))
Method updated_record_with_column
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def updated_record_with_column(column, value, scope)
record = params[:id] ? copy_attributes(find_if_allowed(params[:id], :read)) : new_model
apply_constraints_to_record(record) unless scope || params[:id]
create_association_with_parent record, check_match: true if nested?
if @form_action == :field_search && value.is_a?(Array) && column.association&.singular?
- 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 active_scaffold_input_ancestry
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def active_scaffold_input_ancestry(column, options, ui_options: column.options)
record = options[:object]
select_options = []
select_control_options = {selected: record.parent_id}
select_control_options[:include_blank] = as_(:_select_) if record.parent_id.nil?
- 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 render_field_for_update_columns
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def render_field_for_update_columns
return if (@column = active_scaffold_config.columns[params.delete(:column)]).nil?
@columns = @column.update_columns || []
@columns << @column.name if @column.options[:refresh_link] && @columns.exclude?(@column.name)
- 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 create_association_with_parent
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def create_association_with_parent(record, check_match: false)
return unless create_association_with_parent?(check_match: check_match)
if nested.child_association&.singular?
record.send(:"#{nested.child_association.name}=", nested_parent_record)
- 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"