Method advanced_search_condition_summary
has a Cognitive Complexity of 89 (exceeds 5 allowed). Consider refactoring. Open
def advanced_search_condition_summary(opts = {})
return "(#{I18n.t('page.new_resource')})" if params[:mode] == 'recent'
return "(#{params[:solr_query]})" if params[:solr_query].present?
summary_ary = []
- 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 enju_trunk_helper.rb
has 668 lines of code (exceeds 250 allowed). Consider refactoring. Open
module EnjuTrunk
module EnjuTrunkHelper
extend ActiveSupport::Concern
included do
Method build_select2
has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring. Open
def build_select2(selector_id, selector_name, collection, selected_id, options)
include_blank = options[:include_blank] || false
alt_display = options.has_key?(:alt_display) ? options[:alt_display] : true
width = options[:width] || 300
select_attribute = options[:select_attribute] || :v
- 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 advanced_search_condition_summary
has 94 lines of code (exceeds 25 allowed). Consider refactoring. Open
def advanced_search_condition_summary(opts = {})
return "(#{I18n.t('page.new_resource')})" if params[:mode] == 'recent'
return "(#{params[:solr_query]})" if params[:solr_query].present?
summary_ary = []
Method agents_list
has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring. Open
def agents_list(relations = [], options = {}, manifestation_id = nil, type = nil, mode = 'html')
return nil if relations.blank?
agents_list = []
exclude_agents = SystemConfiguration.get("exclude_agents").split(',').inject([]){ |list, word| list << word.gsub(/^[ \s]*(.*?)[ \s]*$/, '\1') }
relations.each do |relation|
- 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 hidden_advanced_search_field_tags
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
def hidden_advanced_search_field_tags
array = []
ADVANCED_SEARCH_PARAMS.map do |name|
if name == :manifestation_types
next unless params[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 build_select2
has 54 lines of code (exceeds 25 allowed). Consider refactoring. Open
def build_select2(selector_id, selector_name, collection, selected_id, options)
include_blank = options[:include_blank] || false
alt_display = options.has_key?(:alt_display) ? options[:alt_display] : true
width = options[:width] || 300
select_attribute = options[:select_attribute] || :v
Method tab_menu_width
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def tab_menu_width
# ライブラリアン権限時未満のとき、タブメニューの表示内容に伴いタブのサイズも変更する
if user_signed_in?
unless current_user.has_role?('Librarian')
# ゲスト権限以上ユーザ権限未満でログイン時
- 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 advanced_search_merge_tag
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
def advanced_search_merge_tag(name, type = nil)
pname = :"#{name}_merge"
all = any = exact = startwith = false
case params[pname]
Method advanced_search_merge_tag
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def advanced_search_merge_tag(name, type = nil)
pname = :"#{name}_merge"
all = any = exact = startwith = false
case params[pname]
- 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 term_check
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def term_check(start_d, end_d)
return t('page.exstatistics.nil_date') if start_d.blank? or end_d.blank?
return t('page.exstatistics.invalid_input_date') unless start_d =~ /^((\d+)-?)*\d$/
return t('page.exstatistics.invalid_input_date') unless end_d =~ /^((\d+)-?)*\d$/
return t('page.exstatistics.invalid_input_date') if date_format_check(start_d) == 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 select2_tag
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def select2_tag(selector_id, selector_name, collection, selected_id, *options)
options = options.first # if options.is_a?(Array)
select2_options = options[:select2options] || {}
if options[:placeholder]
select2_options[:placeholder] = '"' + escape_javascript(options.delete(:placeholder)) + '"'
- 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 agents_short_list
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def agents_short_list(agents = [], options = {})
return nil if agents.blank?
agents_list = []
agents.each_with_index do |agent, i|
if i < 3
- 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 get_detail_name
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def get_detail_name(model, primary, secondary = '')
return '' if model.blank? or primary.blank?
name_ary = model.display_name.localize.split(/[,:]/, -1) rescue []
return name_ary.first if name_ary.size.odd?
name_hash = Hash[*name_ary]
- 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 link_to_normal_search
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def link_to_normal_search(link_title = nil)
if params[:mode].present?
return '' if params[:mode] != 'recent'
else
return '' if ADVANCED_SEARCH_PARAMS.all? {|k| params[k].blank? } and params[:solr_query].blank?
- 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_select2
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def build_select2(selector_id, selector_name, collection, selected_id, options)
Method agents_list
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def agents_list(relations = [], options = {}, manifestation_id = nil, type = nil, mode = 'html')
Method select2_tag
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def select2_tag(selector_id, selector_name, collection, selected_id, *options)
Avoid too many return
statements within this method. Open
return t('page.exstatistics.invalid_input_date') if date_format_check(end_d) == nil
Avoid too many return
statements within this method. Open
return t('page.exstatistics.over_end_date') if end_d.gsub(/\D/, '') < start_d.gsub(/\D/, '')
Method back_to_index
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def back_to_index(options = {})
if options == nil
options = {}
else
options.reject!{|key, value| value.blank?}
- 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
if select_attribute.instance_of?(Array)
if select_attribute[1].instance_of?(Array)
relations = select_attribute[1].inject('row') { |str, i| str + ".send('#{i}')" }
row_select_attribute = eval("#{relations}.send(select_attribute[0])")
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 45.
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 display_attribute.instance_of?(Array)
if display_attribute[1].instance_of?(Array)
relations = display_attribute[1].inject('row') { |str, i| str + ".send('#{i}')" }
row_display_attribute = eval("#{relations}.send(display_attribute[0])")
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 45.
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