Showing 368 of 368 total issues
Similar blocks of code found in 3 locations. Consider refactoring. Open
var selection = $('#purposes'),
args = {
selection: selection,
data: data.purposes,
condition: function (item) {return item.code},
- 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 102.
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 3 locations. Consider refactoring. Open
var selection = $('#terms'),
args = {
selection: selection,
data: data.terms,
condition: function (item) {return item.code},
- 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 102.
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 3 locations. Consider refactoring. Open
var selection = $('#sources'),
args = {
selection: selection,
data: data.sources,
condition: function (item) {return item.code},
- 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 102.
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
Class DocumentSearch
has 27 methods (exceeds 20 allowed). Consider refactoring. Open
class DocumentSearch
# NOTE!!! This class returns an unpaginated result. Not sure if pagination can be restored
# and it is currently being done on the unpaginated query results in the API and web
# documents #index endpoints.
include CacheIterator
File compliance.rb
has 296 lines of code (exceeds 250 allowed). Consider refactoring. Open
class Trade::Grouping::Compliance < Trade::Grouping::Base
# Complete up to current year - 1
COUNTRIES = {
2022 => 183,
Class Output
has 26 methods (exceeds 20 allowed). Consider refactoring. Open
class NomenclatureChange::Output < ApplicationRecord
include TrackWhoDoesIt
attr_accessor :output_type # New taxon, Existing subspecies, Existing taxon
# Migrated to controller (Strong Parameters)
# attr_accessible :nomenclature_change_id, :taxon_concept_id,
Class MandatoryQuotasShipments
has 26 methods (exceeds 20 allowed). Consider refactoring. Open
class Trade::MandatoryQuotasShipments
attr_reader :final_query
QUOTAS_PATH = 'lib/data/quotas.csv'.freeze
Class ShowTaxonConceptSerializer
has 26 methods (exceeds 20 allowed). Consider refactoring. Open
class Species::ShowTaxonConceptSerializer < ActiveModel::Serializer
cached
root 'taxon_concept'
attributes :id, :parent_id, :full_name, :author_year, :standard_references,
:common_names, :distributions, :subspecies, :distribution_references,
Method error_message
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
def error_message(values_hash = nil)
scope_info = sanitized_sandbox_scope.map do |scope_column, scope_def|
tmp = []
if scope_def['inclusion']
tmp << "#{scope_column} = #{scope_def['inclusion'].join(', ')}"
- 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 copied_object_before_save
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
def copied_object_before_save(reassignment, reassignable)
return nil if conflicting_listing_change_reassignment?(reassignment, reassignable)
new_taxon_concept = @output.new_taxon_concept || @output.taxon_concept
Rails.logger.debug("Processing #{reassignable.class} #{reassignable.id} copy to #{new_taxon_concept.full_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_indexes_on_shipments
has 71 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.create_indexes_on_shipments
sql = <<-SQL
CREATE INDEX index_trade_shipments_on_appendix
ON trade_shipments
USING btree
Method raw_query
has 70 lines of code (exceeds 25 allowed). Consider refactoring. Open
def raw_query(options)
"SELECT
shipments.id,
year,
appendix,
Method index
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
def index
if params[:taxon_concept_query].present?
exact_match = MTaxonConcept.where("LOWER(full_name) = ?", params[:taxon_concept_query].downcase)
.where(taxonomy_id: 1)
.first
- 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 ar_klass
has 68 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.ar_klass(table_name)
klass_name = table_name.camelize
begin
"Trade::#{klass_name}".constantize
rescue NameError
Method run_final_queries
has 68 lines of code (exceeds 25 allowed). Consider refactoring. Open
def run_final_queries
# need to duplicate CoP documents, which are linked to more than one proposal
# that applies to old documents
sql = <<-SQL
WITH proposal_details AS (
Method partial_db_query
has 66 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.partial_db_query(limit, offset, updated_at: nil, created_at: nil)
full_db_query(limit, offset) unless updated_at || created_at
where = if updated_at && !created_at
"shipments.updated_at > '#{updated_at}'"
elsif created_at && !updated_at
Method cites_listing_changes
has 66 lines of code (exceeds 25 allowed). Consider refactoring. Open
def cites_listing_changes
rel = MCitesListingChange.from('api_cites_listing_changes_view AS listing_changes_mview').
where(
'listing_changes_mview.taxon_concept_id' => object_and_children
)
Method eu_listing_changes
has 65 lines of code (exceeds 25 allowed). Consider refactoring. Open
def eu_listing_changes
rel = MEuListingChange.from('api_eu_listing_changes_view AS listing_changes_mview').
where(
'listing_changes_mview.taxon_concept_id' => object_and_children
)
Method run_queries
has 65 lines of code (exceeds 25 allowed). Consider refactoring. Open
def run_queries
ApplicationRecord.connection.execute('DROP TABLE IF EXISTS elibrary_citations_resolved_tmp')
ApplicationRecord.connection.execute('CREATE TABLE elibrary_citations_resolved_tmp (document_id INT, CitationId INT, CtyISO2 TEXT, splus_taxon_concept_id INT)')
ApplicationRecord.connection.execute(
<<-SQL
Method shipment_in_scope?
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def shipment_in_scope?(shipment)
shipment_in_scope = true
# check if shipment is in scope of this validation
sanitized_shipments_scope.each do |scope_column, scope_def|
value = shipment.send(scope_column)
- 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"