Method has too many lines. [50/25] Open
def row_hash_initiate
h = {}
rows = nil # Of either Otu or ObservationMatrixRow of type Otu !! TODO:
if observation_matrix_id.to_i == 0 && !otu_filter.blank?
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Method row_hash_initiate
has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring. Open
def row_hash_initiate
h = {}
rows = nil # Of either Otu or ObservationMatrixRow of type Otu !! TODO:
if observation_matrix_id.to_i == 0 && !otu_filter.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
File image_matrix.rb
has 302 lines of code (exceeds 250 allowed). Consider refactoring. Open
class Tools::ImageMatrix
##### FILTER PARAMETERS #####
# @!observation_matrix_id
Method descriptors_hash_initiate
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
def descriptors_hash_initiate
h = {}
# Depictions is depictions with other attributes added
depictions = 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 has too many lines. [35/25] Open
def descriptors_hash_initiate
h = {}
# Depictions is depictions with other attributes added
depictions = nil
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Method has too many lines. [34/25] Open
def build_image_hash
# if !otu_filter.blank? || !row_filter.blank?
# img_ids = observation_depictions_from_otu_filter.pluck(:image_id).uniq
# else
# img_ids = observation_matrix.observation_depictions.pluck(:image_id).uniq
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Method row_hash_initiate
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
def row_hash_initiate
h = {}
rows = nil # Of either Otu or ObservationMatrixRow of type Otu !! TODO:
if observation_matrix_id.to_i == 0 && !otu_filter.blank?
Method descriptors_hash_initiate
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
def descriptors_hash_initiate
h = {}
# Depictions is depictions with other attributes added
depictions = nil
Method build_image_hash
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
def build_image_hash
# if !otu_filter.blank? || !row_filter.blank?
# img_ids = observation_depictions_from_otu_filter.pluck(:image_id).uniq
# else
# img_ids = observation_matrix.observation_depictions.pluck(:image_id).uniq
Method rows_with_filter
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def rows_with_filter
return @rows_with_filter if !@rows_with_filter.nil?
@rows_with_filter = [] if observation_matrix.nil?
if !row_id_filter_array.nil?
@rows_with_filter ||= observation_matrix.observation_matrix_rows.where(id: row_id_filter_array).order(:position)
- 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
Consider simplifying this complex logical expression. Open
if (row_id_filter_array.nil? && otu_id_filter_array.nil?) ||
(row_id_filter_array && row_id_filter_array.include?(r_value[:object].id)) ||
(otu_id_filter_array && otu_id_filter_array.include?(r_value[:otu_id]))
h[r_key] = {object: r_value[:object_at_rank],
row_id: r_value[:object].id,
Method descriptors_with_keywords
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def descriptors_with_keywords
if observation_matrix_id.to_i == 0 && !otu_filter.blank?
d = observation_depictions_from_otu_filter.pluck(:descriptor_id).uniq
ds = Descriptor.where("descriptors.type = 'Descriptor::Media' AND descriptors.id IN (?)", d).not_weight_zero
elsif keyword_ids
- 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 selected_descriptors_hash_initiate
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def selected_descriptors_hash_initiate
# "123:1|3||125:3|5||135:2"
h = {}
return h if selected_descriptors.blank?
a = selected_descriptors.include?('||') ? selected_descriptors.to_s.split('||') : [selected_descriptors]
- 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
Use per.presence || 250
instead of per.blank? ? 250 : per
. Open
@per = per.blank? ? 250 : per
- Read upRead up
- Exclude checks
This cop checks code that can be written more easily using
Object#presence
defined by Active Support.
Example:
# bad
a.present? ? a : nil
# bad
!a.present? ? nil : a
# bad
a.blank? ? nil : a
# bad
!a.blank? ? a : nil
# good
a.presence
Example:
# bad
a.present? ? a : b
# bad
!a.present? ? b : a
# bad
a.blank? ? b : a
# bad
!a.blank? ? a : b
# good
a.presence || b
Use page.presence || 1
instead of page.blank? ? 1 : page
. Open
@page = page.blank? ? 1 : page
- Read upRead up
- Exclude checks
This cop checks code that can be written more easily using
Object#presence
defined by Active Support.
Example:
# bad
a.present? ? a : nil
# bad
!a.present? ? nil : a
# bad
a.blank? ? nil : a
# bad
!a.blank? ? a : nil
# good
a.presence
Example:
# bad
a.present? ? a : b
# bad
!a.present? ? b : a
# bad
a.blank? ? b : a
# bad
!a.blank? ? a : b
# good
a.presence || b
Use otu_filter.present?
instead of !otu_filter.blank?
. Open
if observation_matrix_id.to_i == 0 && !otu_filter.blank?
- Read upRead up
- Exclude checks
This cop checks for code that can be written with simpler conditionals
using Object#present?
defined by Active Support.
Interaction with Style/UnlessElse
:
The configuration of NotBlank
will not produce an offense in the
context of unless else
if Style/UnlessElse
is inabled. This is
to prevent interference between the auto-correction of the two cops.
Example: NotNilAndNotEmpty: true (default)
# Converts usages of `!nil? && !empty?` to `present?`
# bad
!foo.nil? && !foo.empty?
# bad
foo != nil && !foo.empty?
# good
foo.present?
Example: NotBlank: true (default)
# Converts usages of `!blank?` to `present?`
# bad
!foo.blank?
# bad
not foo.blank?
# good
foo.present?
Example: UnlessBlank: true (default)
# Converts usages of `unless blank?` to `if present?`
# bad
something unless foo.blank?
# good
something if foo.present?
Use otu_filter.present?
instead of !otu_filter.blank?
. Open
if observation_matrix_id.to_i == 0 && !otu_filter.blank?
- Read upRead up
- Exclude checks
This cop checks for code that can be written with simpler conditionals
using Object#present?
defined by Active Support.
Interaction with Style/UnlessElse
:
The configuration of NotBlank
will not produce an offense in the
context of unless else
if Style/UnlessElse
is inabled. This is
to prevent interference between the auto-correction of the two cops.
Example: NotNilAndNotEmpty: true (default)
# Converts usages of `!nil? && !empty?` to `present?`
# bad
!foo.nil? && !foo.empty?
# bad
foo != nil && !foo.empty?
# good
foo.present?
Example: NotBlank: true (default)
# Converts usages of `!blank?` to `present?`
# bad
!foo.blank?
# bad
not foo.blank?
# good
foo.present?
Example: UnlessBlank: true (default)
# Converts usages of `unless blank?` to `if present?`
# bad
something unless foo.blank?
# good
something if foo.present?
Use ds.blank?
instead of ds.nil? || ds.empty?
. Open
return [] if ds.nil? || ds.empty?
- Read upRead up
- Exclude checks
This cop checks for code that can be written with simpler conditionals
using Object#blank?
defined by Active Support.
Interaction with Style/UnlessElse
:
The configuration of NotPresent
will not produce an offense in the
context of unless else
if Style/UnlessElse
is inabled. This is
to prevent interference between the auto-correction of the two cops.
Example: NilOrEmpty: true (default)
# Converts usages of `nil? || empty?` to `blank?`
# bad
foo.nil? || foo.empty?
foo == nil || foo.empty?
# good
foo.blank?
Example: NotPresent: true (default)
# Converts usages of `!present?` to `blank?`
# bad
!foo.present?
# good
foo.blank?
Example: UnlessPresent: true (default)
# Converts usages of `unless present?` to `if blank?`
# bad
something unless foo.present?
# good
something if foo.blank?
# bad
unless foo.present?
something
end
# good
if foo.blank?
something
end
# good
def blank?
!present?
end
Use otu_filter.present?
instead of !otu_filter.blank?
. Open
if observation_matrix_id.to_i == 0 && !otu_filter.blank?
- Read upRead up
- Exclude checks
This cop checks for code that can be written with simpler conditionals
using Object#present?
defined by Active Support.
Interaction with Style/UnlessElse
:
The configuration of NotBlank
will not produce an offense in the
context of unless else
if Style/UnlessElse
is inabled. This is
to prevent interference between the auto-correction of the two cops.
Example: NotNilAndNotEmpty: true (default)
# Converts usages of `!nil? && !empty?` to `present?`
# bad
!foo.nil? && !foo.empty?
# bad
foo != nil && !foo.empty?
# good
foo.present?
Example: NotBlank: true (default)
# Converts usages of `!blank?` to `present?`
# bad
!foo.blank?
# bad
not foo.blank?
# good
foo.present?
Example: UnlessBlank: true (default)
# Converts usages of `unless blank?` to `if present?`
# bad
something unless foo.blank?
# good
something if foo.present?
TODO found Open
rows = nil # Of either Otu or ObservationMatrixRow of type Otu !! TODO:
- Exclude checks
TODO found Open
# TODO: CHANGED FLAG REMOVE
- Exclude checks
Identical blocks of code found in 2 locations. Consider refactoring. Open
def language_to_use
return nil if language_id.blank?
l = Language.where(id: language_id).first
return nil if l.nil? || !descriptor_available_languages.to_a.include?(l)
l
- 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 26.
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
Prefer single-quoted strings when you don't need string interpolation or special symbols. Open
.joins("INNER JOIN images ON depictions.image_id = images.id")
- Read upRead up
- Exclude checks
Checks if uses of quotes match the configured preference.
Example: EnforcedStyle: single_quotes (default)
# bad
"No special symbols"
"No string interpolation"
"Just text"
# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"
Example: EnforcedStyle: double_quotes
# bad
'Just some text'
'No special chars or interpolation'
# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"
Prefer single-quoted strings when you don't need string interpolation or special symbols. Open
.joins("INNER JOIN observations ON observations.id = depictions.depiction_object_id")
- Read upRead up
- Exclude checks
Checks if uses of quotes match the configured preference.
Example: EnforcedStyle: single_quotes (default)
# bad
"No special symbols"
"No string interpolation"
"Just text"
# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"
Example: EnforcedStyle: double_quotes
# bad
'Just some text'
'No special chars or interpolation'
# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"
Prefer single-quoted strings when you don't need string interpolation or special symbols. Open
.joins("LEFT OUTER JOIN sources ON citations.source_id = sources.id")
- Read upRead up
- Exclude checks
Checks if uses of quotes match the configured preference.
Example: EnforcedStyle: single_quotes (default)
# bad
"No special symbols"
"No string interpolation"
"Just text"
# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"
Example: EnforcedStyle: double_quotes
# bad
'Just some text'
'No special chars or interpolation'
# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"