Showing 1,155 of 1,155 total issues
Similar blocks of code found in 5 locations. Consider refactoring. Open
def create
@publication_status = PublicationStatus.new(params[:publication_status])
respond_to do |format|
if @publication_status.save
- 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 36.
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 reservable_with_item?
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def reservable_with_item?(user = nil) #TODO reservabl? メソッドと重複?
#TODO reserve.not_reserve_on_loan 変数名と実態が異なる
# true で 貸出中のみ予約可能
if SystemConfiguration.get("reserve.not_reserve_on_loan")
return true if user.try(: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 get_manifestation_reserve_stats_tsv
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def self.get_manifestation_reserve_stats_tsv(manifestation_reserve_stat, stats)
data = String.new
data << "\xEF\xBB\xBF".force_encoding("UTF-8") + "\n"
# term
- 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_order_date
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def self.check_order_date(start_at, end_at)
if start_at.present? && end_at.present?
begin
start_at_new = Time.zone.parse(start_at)
end_at_new = Time.zone.parse(end_at)
- 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_manifestation_checkout_stats_tsv
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def self.get_manifestation_checkout_stats_tsv(manifestation_checkout_stat, stats)
data = String.new
data << "\xEF\xBB\xBF".force_encoding("UTF-8") + "\n"
# manifestation_checkout_stat
- 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 _removeString
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
_removeString: function(new_input) {
if(new_input.match(this.ignoreString)) {
return new_input.replace(this.ignoreString, '');
} else {
var i, l, ignoreArray, inputArray;
- 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 generate_resource_import_textresult_list
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def self.generate_resource_import_textresult_list(resource_import_textresults, output_type, current_user, &block)
threshold ||= Setting.background_job.threshold.export rescue nil
# 出力件数の計算
all_size = resource_import_textresults.count
- 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 read_wrong_format
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def self.read_wrong_format(filename, options = { sheet: nil, default_style: nil, data: nil })
split = SystemConfiguration.get('set_output_format_type') ? "\t" : ","
#file = Tsvfile_Adapter.new.open_import_file(filename)
tempfile = Tempfile.new('resource_import_file')
if Setting.uploaded_file.storage == :s3
- 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 make_export_new_item_list_tsv
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def self.make_export_new_item_list_tsv(items)
data = String.new
data << "\xEF\xBB\xBF".force_encoding("UTF-8") + "\n"
# set term
- 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_manifestation_list_separated_column_count
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def self.get_manifestation_list_separated_column_count(manifestation_ids, field_key, outer_cache = {})
field, field_ext = field_key.split(/\./, 2)
case field_ext
when /\Aother_title(?:_type|_transcription|_alternativ|_transcription|_alternativee)?\z/
- 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 change_state_on_order
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def change_state_on_order
ordered_state = CirculationStatus.where(name: "On Ordered").first
if ordered_state
if self.orders
- 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_query
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def build_query(cond, inverse = false)
if inverse
op = 'OR'
else
op = 'AND'
- 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 import_agents
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def self.import_agents(agent_lists, options = {})
list = []
return list if agent_lists.blank?
options[:language_id] ||= 1
- 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 set_date_of_publication
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def set_date_of_publication
return if pub_date.blank?
begin
date = Time.zone.parse("#{pub_date}")
rescue ArgumentError
- 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_manifestation_from_isbn
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def update_manifestation_from_isbn(manifestation, book_types = ManifestationType.book.all, nacsis_cat = nil, index = nil)
raise ArgumentError if manifestation.blank?
raise ArgumentError if manifestation.isbn.blank?
if nacsis_cat.nil?
result = NacsisCat.search(isbn: manifestation.isbn)
- 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_agents
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def self.add_agents(agent_names, agent_transcriptions = nil, options = {})
return [] if agent_names.blank?
names = agent_names.gsub(';', ';').split(/;/)
if agent_transcriptions.nil?
transcriptions = []
- 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 count_relationship
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def self.count_relationship(agent_id, relation_type_id, parent_child_relationship)
return 0 if agent_id.blank?
if relation_type_id.blank? && parent_child_relationship.blank?
self.where("parent_id = ? OR child_id = ?", agent_id, agent_id).count
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 output_reminder_list_pdf
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def self.output_reminder_list_pdf(reminder_lists)
report = EnjuTrunk.new_report('reminder_list.tlf')
# set page_num
report.events.on :page_create do |e|
- 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 do_order
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def do_order(letter_file_only = false)
# generate order file
order_file_dir = File.join(Rails.root.to_s, 'private', 'system', 'order_letter', "#{self.id}")
order_file_path = File.join(order_file_dir, "order_letter_#{Time.now.strftime("%Y%m%d")}")
FileUtils.mkdir_p(order_file_dir)
- 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 summary
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def summary
return nil unless @record
if item?
hash = {
- 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"