Method columns_to_cells
has a Cognitive Complexity of 101 (exceeds 5 allowed). Consider refactoring. Open
def columns_to_cells(nature, options = {})
code = ''
unless %i[body children].include?(nature)
raise ArgumentError, 'Nature is invalid'
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
File simple_renderer.rb
has 387 lines of code (exceeds 250 allowed). Consider refactoring. Open
module ActiveList
module Renderers
class SimpleRenderer < AbstractRenderer
include ActiveList::Helpers
Method columns_to_cells
has 100 lines of code (exceeds 25 allowed). Consider refactoring. Open
def columns_to_cells(nature, options = {})
code = ''
unless %i[body children].include?(nature)
raise ArgumentError, 'Nature is invalid'
end
Method column_classes
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
def column_classes(column, without_id = false, without_interpolation = false)
classes = []
conds = []
conds << [:sor, "#{var_name(:params)}[:sort] == '#{column.sort_id}'".c] if column.sortable?
conds << [:hidden, "#{var_name(:params)}[:hidden_columns].include?(:#{column.name})".c] if column.is_a? ActiveList::Definition::DataColumn
- 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 build_table_code
has 89 lines of code (exceeds 25 allowed). Consider refactoring. Open
def build_table_code(options = {})
record = 'r'
# colgroup = columns_definition_code
header = header_code
Method extras_codes
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
def extras_codes
code = []
codes = {}
if table.global_action_columns.any?
- 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 build_table_code
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def build_table_code(options = {})
record = 'r'
# colgroup = columns_definition_code
header = header_code
- 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 header_code
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
def header_code
code = ''
code << "'<thead><tr>"
if table.selectable?
code << '<th class="list-selector"><input type="checkbox" data-list-selector="all" /></th>'
- 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 column_classes
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
def column_classes(column, without_id = false, without_interpolation = false)
classes = []
conds = []
conds << [:sor, "#{var_name(:params)}[:sort] == '#{column.sort_id}'".c] if column.sortable?
conds << [:hidden, "#{var_name(:params)}[:hidden_columns].include?(:#{column.name})".c] if column.is_a? ActiveList::Definition::DataColumn
Method extras_codes
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
def extras_codes
code = []
codes = {}
if table.global_action_columns.any?
Method header_code
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
def header_code
code = ''
code << "'<thead><tr>"
if table.selectable?
code << '<th class="list-selector"><input type="checkbox" data-list-selector="all" /></th>'
Method menu_code
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def menu_code
menu = "<span class=\"list-settings\" data-list-ref=\"#{uid}\">"
menu << "<a class=\"settings-start\"><i></i>' + h('list.menu'.t) + '</a>"
menu << '<ul>'
if table.paginate?
Avoid deeply nested control flow statements. Open
currency = :currency if currency.is_a?(TrueClass)
Avoid deeply nested control flow statements. Open
currency = currency[nature] if currency.is_a?(Hash)
Avoid deeply nested control flow statements. Open
column.options[:url] = {} unless column.options[:url].is_a?(Hash)
Avoid deeply nested control flow statements. Open
value_code = (nature == :body ? "text_field_tag(#{form_name.inspect}, #{recordify!(column.options[:value] || column.name, record)}#{column.options[:size] ? ', size: ' + column.options[:size].to_s : ''})" : 'nil') # , id: '#{table.name}_'+#{record}.id.to_s + '_#{column.name}'
Avoid deeply nested control flow statements. Open
elsif column.options[:mode] || column.label_method == :email
value_code = "(#{value_code}.blank? ? '' : mail_to(#{value_code}))"
elsif column.options[:mode] || column.label_method == :website
value_code = "(#{value_code}.blank? ? '' : link_to(" + value_code + ', ' + value_code + '))'
elsif column.label_method == :color
Avoid deeply nested control flow statements. Open
currency = "#{column.record_expr(record)}.#{currency}".c if currency.is_a?(Symbol)
Avoid deeply nested control flow statements. Open
if column.form_value
value = recordify(column.form_value, record)
else
value = 1
value_code << "hidden_field_tag(#{form_name.inspect}, 0, id: nil) + \n"
Avoid deeply nested control flow statements. Open
elsif column.datatype == :decimal
value_code = "(#{value_code}.nil? ? '' : #{value_code}.l)"
elsif column.enumerize?
value_code = "(#{value_code}.nil? ? '' : #{value_code}.text)"
Avoid deeply nested control flow statements. Open
elsif column.is_a?(ActiveList::Definition::ActionColumn)
next unless column.use_single?
value_code = (nature == :body ? column.operation(record) : 'nil')
else
value_code = "' ∅ '.html_safe"
Identical blocks of code found in 2 locations. Consider refactoring. Open
pagination << "<span class=\"status\">' + 'list.pagination.x_to_y_of_total'.t(x: (#{var_name(:offset)} + (#{var_name(:count)} > 0 ? 1 : 0)), y: ((#{var_name(:last)} == #{var_name(:page)}) ? #{var_name(:count)} : #{var_name(:offset)} + #{var_name(:limit)}), total: #{var_name(:count)}) + '</span>"
- 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 35.
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
pagination << "<span class=\"status\">' + 'list.pagination.x_to_y_of_total'.t(x: (#{var_name(:offset)} + (#{var_name(:count)} > 0 ? 1 : 0)), y: ((#{var_name(:last)} == #{var_name(:page)}) ? #{var_name(:count)} : #{var_name(:offset)} + #{var_name(:limit)}), total: #{var_name(:count)}) + '</span>"
- 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 35.
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